PYTHON PROGRAMS 1
1. Write a Python program to find the sum of two numbers.
#Program to find the sum of two given numbers
num1 = 10
num2 = 20
result = num1 + num2
print(result) #print function in python displays the output
Output: 30
2. Write a Python program to find the area of a rectangle given that its length is 10 units and breadth
is 20 units.
#Program to find the area of a rectangle
length = 10
breadth = 20
area = length * breadth
print(area)
Output: 20
3. FileName: print_format_positional_para.py
a,b,c=10,20.5,'30'
print ('a value is {} b value is {} and c values is{}'.format(a,b,c))
print ('a value is {0} b value is {1} and c values is{2}'.format(a,b,c))
Output :
a value is 10 b value is 20.5 and c values is30
a value is 10 b value is 20.5 and c values is30
4. FileName: print_format_keyword_para.py
a,b,c=10,20.5,'30'
print ('a value is {g} b value is {s} and c values is{p}'.format(g=a,s=b,p=c))
Output:
a value is 10 b value is 20.5 and c values is30
PYTHON PROGRAMS 2
[Link] a program to find the average of 3 numbers
# Prompt the user to input three numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
# Calculate the average
average = (num1 + num2 + num3) / 3
# Display the result
print(f"The average of the three numbers is: {average:.2f}")
output:
Enter the first number: 33
Enter the second number: 33
Enter the third number: 22
The average of the three numbers is: 29.33
6. Write a python program that takes principal amount, time and rate of interest from console and
calculate and display simple interest an output.
Hint: simpleinterest=p*t*r/100
#filename: simple_int.py
p=float(input('Enter principal ampount:'))
t=float(input('Enter time:'))
r=float(input('Enter rate of interest:'))
si=p*t*r/100
print('simple interest=',si)
Output:
Enter principal ampount:2000
Enter time:2
Enter rate of interest:12
simple interest= 480.0
PYTHON PROGRAMS 3
7. Write a python program that takes radius of circle as input from console and calculate and display
area and perimeter of circle.
#filename: area_peri_circle.p
r=float(input('Enter radius of circle:'))
area=3.14*r*r
peri=2*3.14*r
print('area of circle=',area)
print('perimeter of circle=',peri)
Output:
Enter radius of circle:5.67
area of circle= 100.94754599999999
perimeter of circle= 35.6076
8. Write a python program that takes temperature in o C (Celsius) as an input and display in
Fahrenheit.
Hint: F=(C*9/5)+32
#filename: Celsius_Fahrenheit.py
c=float(input('Enter temperature in Celsius:'))
f=(c*9/5)+32
print('The given temerature in Faherenheit is=',f)
Output:
Enter temperature in Celsius:32
The given temerature in Faherenheit is= 89.6