Python Programs
1. Positive or Negative Number
num = int(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")
2. Check Even or Odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
3. Largest of Two Numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print("First number is larger")
else:
print("Second number is larger")
4. Grade Finder
marks = int(input("Enter your marks: "))
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Grade D")
5. Simple Login Check
password = input("Enter password: ")
if password == "school123":
print("Login successful")
else:
print("Wrong password")
6. Voting Eligibility
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote")
else:
print("You are not eligible to vote")
7. Number Comparison (Three Numbers)
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a > b and a > c:
print("First is greatest")
elif b > c:
print("Second is greatest")
else:
print("Third is greatest")
8. Check Passing or Failing Marks
marks = int(input("Enter your marks: "))
if marks >= 33:
print("You passed the exam")
else:
print("You failed the exam")
9. Check Age Group
age = int(input("Enter your age: "))
if age <= 12:
print("You are a child")
elif age <= 19:
print("You are a teenager")
else:
print("You are an adult")
10. Favourite Colour
color = input("Enter your favourite colour: ")
print("Wow! " + color + " is a nice colour!")
11. Simple Calculator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("[Link] [Link] [Link] [Link]")
choice = int(input("Enter choice: "))
if choice == 1:
print("Sum =", a + b)
elif choice == 2:
print("Difference =", a - b)
elif choice == 3:
print("Product =", a * b)
elif choice == 4:
print("Quotient =", a / b)
else:
print("Invalid choice")
12. Check Divisibility by 5
num = int(input("Enter a number: "))
if num % 5 == 0:
print("Divisible by 5")
else:
print("Not divisible by 5")
13. Day of the Week
day = int(input("Enter a number (1-7): "))
if day == 1:
print("Monday")
elif day == 2:
print("Tuesday")
elif day == 3:
print("Wednesday")
elif day == 4:
print("Thursday")
elif day == 5:
print("Friday")
elif day == 6:
print("Saturday")
elif day == 7:
print("Sunday")
else:
print("Invalid number")
14. Simple Password Strength
password = input("Enter password: ")
if len(password) >= 8:
print("Strong password")
else:
print("Weak password")
15. Temperature Check
temp = int(input("Enter temperature in °C: "))
if temp > 30:
print("It's Hot")
elif temp >= 20:
print("It's Warm")
else:
print("It's Cold")