MODULE 3
SELECTION USING PYTHON:-
if Statement
if-else Statement
Multi-Way if Statement
Exercises
1. Write a Python program that prompts the user to enter a number and checks if the
number is even or odd. If the number is even, print “The number is even”. If the number
is odd, print “The number is odd”.
2. Write a Python program that takes two numbers as input from the user and prints the
larger of the two numbers. If both numbers are equal, print “The numbers are equal”.
3. Write a Python program that takes a students’ marks as input and prints their grade
based on the following criteria:
• Marks >= 90: A
• Marks 80-89: B
• Marks 70-79: C
• Marks 60-69: D
• Marks <60: F
4. Write a Python program that takes a year as input and checks if the year is a leap year.
• If the year is divisible by 400, it ia a leap year
• If the year is divisible by 100 but not 400, it is not a leap year
• If the year is divisible by 4 but not 100, it is a leap year.
5. Write a Python program that checks the strength of a password entered by the user. The
program should categorize the password as:
• “Weak” if it is less than 6 characters
• “Medium” if it is between 6 and 10 characters
• “Strong” if it is more than 10 characters.
REPETITION STATEMENTS IN PYTHON
Python range( ) Function
Loops that Count Down
Count Control with a while Loop
Loop control statements
break Statement
continue Statement
pass Statement
Difference between pass and continue
Exercises
1. Write a Python program to print numbers from 1 to 10 using a while loop.
2. Write a Python program to calculate the sum of the first N natural numbers using a for
loop. The user will input N.
3. Write a Python program that takes a number as input from the user and finds the
factorial of that number using a while loop.
Random Numbers