Python Programs
Name: Shivang Singh
Class: 10th C
Roll No.: 28
Date: 7th January 2025
1. Program to input a year and find if it is a leap year or not
Python Code:
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(str(year) + " is a leap year.")
else:
print(str(year) + " is not a leap year.")
Expected Outcome:
Input: 2024
Output: 2024 is a leap year.
2. WAP to input sides of a triangle and calculate its area using Heron's formula
Python Code:
print("Area of the triangle =", area)
Expected Outcome:
Input: a = 3, b = 4, c = 5
Output: Area of the triangle = 6.0
3. Write a program to input a number and determine whether it is a prime number or not
Python Code:
print(str(num) + " is not a prime number.")
print(str(num) + " is a prime number.")
Expected Outcome:
Input: 7
Output: 7 is a prime number.
4. Write a program to input the principal, rate, and time to calculate simple interest
Python Code:
print("Simple Interest =", simple_interest)
Expected Outcome:
Input: Principal = 1000, Rate = 5%, Time = 2 years
Output: Simple Interest = 100.0
5. Write a program to input a number and check whether it is even or odd
Python Code:
if num % 2 == 0:
print(str(num) + " is an even number.")
else:
print(str(num) + " is an odd number.")
Expected Outcome:
Input: 4
Output: 4 is an even number.
6. Write a program to convert a temperature from Celsius to Fahrenheit
Python Code:
print("Fahrenheit =", fahrenheit)
Expected Outcome:
Input: Celsius = 0
Output: Fahrenheit = 32.0
7. WAP to print all even numbers from 1 to 100
Python Code:
for i in range(1, 101):
if i % 2 == 0:
print(i, end=", ")
Expected Outcome:
Output: 2, 4, 6, ..., 100
8. Write a program to input a number and check whether it is positive, negative, or zero
Python Code:
num = float(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.")
Expected Outcome:
Input: -5
Output: The number is negative.
9. Write a program to input two numbers and swap their values
Python Code:
print("After swapping: a =", a, ", b =", b)
Expected Outcome:
Input: a = 3, b = 4
Output: a = 4, b = 3
10. Write a program to input a number and display its square
Python Code:
print("Square of", num, "=", square)
Expected Outcome:
Input: 5
Output: Square of 5 = 25