Python Programs and their Outputs for questions 1-10 :
---
1. Positive, Negative, or Zero Check
# Program to check whether a number is positive, negative, or zero
num = float(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
Example Output:
Enter a number: -3
The number is negative.
---
2. Even or Odd Check
# Program to check whether a number is even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
Example Output:
Enter a number: 7
The number is odd.
---
3. Find the Greatest of Three Numbers
# Program to find the greatest of three numbers
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))
if a > b and a > c:
print(f"The greatest number is {a}.")
elif b > c:
print(f"The greatest number is {b}.")
else:
print(f"The greatest number is {c}.")
Example Output:
Enter the first number: 5
Enter the second number: 12
Enter the third number: 9
The greatest number is 12.
---
4. Assign Grades Based on Marks
# Program to assign grades based on marks
marks = int(input("Enter the marks: "))
if marks >= 90:
grade = "A"
elif marks >= 75:
grade = "B"
elif marks >= 50:
grade = "C"
else:
grade = "D"
print(f"The grade is {grade}.")
Example Output:
Enter the marks: 83
The grade is B.
---
5. Leap Year Check
# Program to check if a year is a leap year
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
Example Output:
Enter a year: 2024
2024 is a leap year.
---
6. Print Numbers from 1 to N
# Program to print all numbers from 1 to N
n = int(input("Enter a number N: "))
for i in range(1, n + 1):
print(i, end=" ")
Example Output:
Enter a number N: 5
12345
---
7. Find the Sum of Numbers from 1 to N
# Program to find the sum of numbers from 1 to N using a while loop
n = int(input("Enter a number N: "))
sum = 0
i=1
while i <= n:
sum += i
i += 1
print(f"The sum of numbers from 1 to {n} is {sum}.")
Example Output:
Enter a number N: 5
The sum of numbers from 1 to 5 is 15.
---
8. Print Odd Numbers Between 20 and 70
# Program to print odd numbers between 20 and 70
for i in range(21, 70, 2): # Start from 21, increment by 2
print(i, end=" ")
Example Output:
21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69
---
9. Print Squares of Numbers from 1 to N
# Program to print squares of numbers from 1 to N
n = int(input("Enter a number N: "))
for i in range(1, n + 1):
print(f"Square of {i} is {i**2}")
Example Output:
Enter a number N: 4
Square of 1 is 1
Square of 2 is 4
Square of 3 is 9
Square of 4 is 16
---
10. Print Numbers from 50 to 40 Using While Loop
# Program to print numbers from 50 to 40 using a while loop
i = 50
while i >= 40:
print(i, end=" ")
i -= 1
Example Output:
50 49 48 47 46 45 44 43 42 41 40