Sample programs - Python
9. To Check whether it is leap year or not
Aim:
To a write a python program to check whether the given year is leap year or not.
Coding:
year = 2024
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
Result:
Thus the given program has been executed successfully.
10. List even numbers from 1to20
Aim:
To a write a python program to list the even numbers from 1 to 20.
Coding :
evens = [i for i in range(1, 21) if i % 2 == 0]
print(evens)
11. Find the average of numbers
Aim:
To a write a python program to find the average of given numbers.
Coding:
nums = [10, 20, 30, 40]
average = sum(nums) / len(nums)
print("Average =", average)
12. To check whether the number is palindrome or not
Aim:
To a write a python program to check whether the given number is palindrome or
not.
Coding:
num = int(input("Enter a number: "))
original = num
rev = 0
while num > 0:
digit = num % 10
rev = rev * 10 + digit
num //= 10
if rev == original:
print("Palindrome")
else:
print("Not Palindrome")
13. Student Grade Management system
Aim:
To write a python program to calculate the grades for the students based on their
marks.
Coding:
marks = float(input("Enter your marks: "))
if marks >= 90:
grade = "A"
elif marks >= 80:
grade = "B"
elif marks >= 70:
grade = "C"
elif marks >= 60:
grade = "D"
else:
grade = "Fail"
print("Your Grade is:", grade)
14. To check the eligibility to vote
Aim:
To a write a python program to check the eligibility to vote.
Coding:
age = int(input("Enter your age: "))
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible to vote")
15. To check the number is a multiple of 5
Aim:
To a write a python program to check the given number is a multiple of 5 or not.
Coding:
num = int(input("Enter a number: "))
if num % 5 == 0:
print("Multiple of 5")
else:
print("Not a multiple of 5")
16. Number classification [Postive , Negative or Zero]
Aim:
To write a python program to classify whether a number is positive, negative or
zero.
Coding:
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
17. To display Traffic light signal color meaning
Aim:
To a write a python program to display the meaning of traffic light colors based on
user input.
Coding:
signal = input("Enter signal color (red/yellow/green): ").lower()
if signal == "red":
print("Stop")
elif signal == "yellow":
print("Slow down")
elif signal == "green":
print("Go")
else:
print("Invalid signal color")
18.To display the days of the week based on numbers
Aim:
To a write a python program to display the days of the week based on the numbers.
Coding:
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 input!")