Simple Python Exercises
Exercise 1: Positive, Negative, or Zero
Write a program that asks the user for a number and checks:
• If it’s positive
• If it’s negative
• Or if it’s zero
Expected Input/Output:
Exercise 2: Even or Odd
Write a program to check whether a given number is even or odd using the modulus (%)
operator.
Expected Input/Output:
Exercise 3: Simple Calculator
Write a program that takes two numbers from the user and prints:
• Their sum
• Their difference
• Their product
• Their quotient
Expected Input/Output:
Exercise 4: Grade Checker
Write a program that asks the user for their marks (0–100).
• If marks ≥ 90 → Print “Grade A”
• If marks ≥ 75 → Print “Grade B”
• If marks ≥ 50 → Print “Grade C”
• Else → Print “Fail”
Expected Input/Output:
Exercise 5: Largest of Three Numbers
Write a program that asks the user to enter three numbers and prints the largest number
using if–else.
Expected Input/Output:
Python Practice Exercises (Set 2)
Exercise 1: Temperature Check
Ask the user to enter the current temperature.
• If temp ≥ 30 → print "It's Hot"
• If temp between 15 and 29 → print "It's Warm"
• Else → print "It's Cold"
Exercise 2: Number Divisible Check
Take a number as input and check:
• If divisible by 5 → print "Divisible by 5"
• Else → print "Not divisible by 5"
Exercise 3: Simple Discount Calculator
Ask the user for the bill amount.
• If bill ≥ 1000 → give 10% discount
• Else → no discount
• Print the final amount.
Exercise 4: Leap Year Checker
Take a year as input.
• If divisible by 400 → Leap year
• Else if divisible by 4 but not 100 → Leap year
• Else → Not a leap year
Exercise 5: Login System
Ask the user to enter a username and password.
• If username = "admin" and password = "1234" → print "Login Successful"
• Else → print "Login Failed"
Exercise 6: Rectangle or Square
Take input for length and width.
• If length == width → print "It's a Square"
• Else → print "It's a Rectangle"