0% found this document useful (0 votes)
7 views

Python Programs(Tanish)

Uploaded by

dr.com1920
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Programs(Tanish)

Uploaded by

dr.com1920
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

Write a program to check whether


the number is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

OUTPUT:-
Enter a number: 8
The number is even.
>>>
2.Write a program to find the sum of
five numbers.
numbers = [int(input(f"Enter number {i+1}: ")) for i in range(5)]
total = sum(numbers)
print("The sum of the five numbers is:", total)

OUTPUT:-
Enter number 1: 5
Enter number 2: 5
Enter number 3: 7
Enter number 4: 8
Enter number 5: 4
The sum of the five numbers is: 29
>>>
3.Write a program to calculate the area
and circumference of a circle:-
import math
radius = float(input("Enter the radius of the circle: "))
area = math.pi * radius ** 2
circumference = 2 * math.pi * radius
print("Area of the circle:", area)
print("Circumference of the circle:", circumference)

OUTPUT:-
Enter the radius of the circle: 5
Area of the circle: 78.53981633974483
Circumference of the circle: 31.41592653589793
>>>
4.Write a program to check the number
is prime or not.
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, num):
if num % i == 0:
print("The number is not prime.")
break
else:
print("The number is prime.")
else:
print("The number is not prime.")

OUTPUT:-
Enter a number: 5
The number is prime.
>>>
5.Write a program to check year is leap
or not.
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print("It is a leap year.")
else:
print("It is not a leap year.")

OUTPUT:-
Enter a year: 2007
It is not a leap year.
>>>
6.Write a program to print the highest
number from the three numbers.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
print("The highest number is:", max(a, b, c))

OUTPUT:-
Enter first number: 5
Enter second number: 7
Enter third number: 4
The highest number is: 7
>>>
7.Write a program to print the table of
any number`

num = int(input("Enter a number: "))


for i in range(1, 11):
print(f"{num} x {i} = {num * i}")

OUTPUT:-

Enter a number: 5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
8.Write a program to print the sum and
multiplication of three number.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
print("Sum:", a + b + c)
print("Multiplication:", a * b * c)

OUTPUT:-

Enter first number: 5


Enter second number: 6
Enter third number: 7
Sum: 18
Multiplication: 210
>>>
9.Write a program to find the area and
perimeter of a rectangle.
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area:", area)
print("Perimeter:", perimeter)

OUTPUT:-
Enter the length of the rectangle: 67
Enter the breadth of the rectangle: 87
Area: 5829.0
Perimeter: 308.0
>>>
10.Write a program to check the
number is multiple of five or not.(Only
for positive number).

num = int(input("Enter a positive number: "))


if num > 0:
if num % 5 == 0:
print("The number is a multiple of five.")
else:
print("The number is not a multiple of five.")
else:
print("Please enter a positive number.")

OUTPUT:-

Enter a positive number: 5


The number is a multiple of five.
>>>

You might also like