50 Simple Easy Python Programs with Answers
1. Check if number is positive, negative or zero
num = 3
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
2. Check if number is even or odd
num = 4
print("Even" if num % 2 == 0 else "Odd")
3. Check if a year is a leap year
year = 2024
print("Leap year" if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) else "Not a leap year")
4. Find greatest of 3 numbers
a, b, c = 10, 20, 5
print(max(a, b, c))
5. Check if character is vowel or consonant
char = 'e'
print("Vowel" if char.lower() in 'aeiou' else "Consonant")
6. Check if a person is eligible to vote
age = 18
print("Eligible" if age >= 18 else "Not eligible")
7. Check if number is divisible by 5 and 11
num = 55
print("Divisible" if num % 5 == 0 and num % 11 == 0 else "Not divisible")
8. Check if character is uppercase or lowercase
ch = 'A'
print("Uppercase" if ch.isupper() else "Lowercase")
9. Simple grading system
marks = 85
if marks >= 90:
grade = 'A'
elif marks >= 75:
grade = 'B'
elif marks >= 60:
grade = 'C'
else:
grade = 'D'
print(grade)
10. Check if a number is in a range
n = 10
print("In range" if 1 <= n <= 100 else "Out of range")