Python Programs
# 1. Simple Addition, Subtraction, Multiplication and Division in Python by Input Method
a=int(input('Enter the First Number :'))
b=int(input('Enter the Second Number :'))
# For Addition
sum = a + b
print('Sum of two numbers : ', sum)
# For Subtraction
sub = a - b
print('Subtraction :', sub)
# For Multiplication
mul=a*b
print('Multiply a and b :', mul)
# For Division
div = a/b
print('Division :', div)
Output:
Enter the First Number :10
Enter the Second Number :5
Sum of two numbers : 15
Subtraction : 5
Multiply a and b : 50
Division : 2.0
# 2. WAP to obtain three numbers and print their sum.
x = int(input('Enter the first number :'))
y = int(input('Enter the second number :'))
z = int(input('Enter the third number :'))
sum = x+y+z
print('Sum of thre numbers are : ', sum)
Output:
Enter the first number :50
Enter the second number :40
Enter the third number :60
Sum of thre numbers are : 150
# 3. WAP to obtain length and breadth of a rectangle and calculate its area.
length = float(input('Enter the length :'))
breadth = float(input('Enter the breadth :'))
Area = length * breadth
print('Area of Rectangle :', Area)
Output:
Enter the length :5.5
Enter the breadth :7.8
Area of Rectangle : 42.9
# 4.WAP to calculate Body Mass Index (BMI) of a person.
weight = float(input('Enter the person weight in kg. : '))
height = float(input('Enter the person height in meters :'))
#Formula
BMI = weight/(height*height)
print('BMI of a person is :', BMI)
Output:
Enter the person weight in kg. : 50
Enter the person height in meters :1.8
BMI of a person is : 15.432098765432098
# 5. WAP to input a number and print its cube.
a = int(input('Enter any number :'))
cube = a*a*a
print('Cube of', a, 'is :', cube)
# 6. WAP to input two numbers and swap them.
a = int(input('Enter the first number :'))
b= int(input('Enter the second number :'))
print('Your Original number :', a , b)
a, b = b, a
print('After swapping:', a, b)
Output:
Enter the first number :10
Enter the second number :20
Your Original number : 10 20
After swapping: 20 10
# 6. WAP to find the average of five numbers.
a = int(input('Enter the first number :'))
b = int(input('Enter the second number :'))
c = int(input('Enter the third number :'))
d = int(input('Enter the fourth number :'))
e = int(input('Enter the fifth number :'))
avg = (a+b+c+d+e)/5
print('Average of five numbers :', avg)
Output:
Enter the first number :60
Enter the second number :65
Enter the third number :70
Enter the fourth number :80
Enter the fifth number :82
Average of five numbers : 71.4
# 7.Print Multiplication Table
def print_multiplication_table(n):
for i in range(1, 11):
for j in range(1, n+1):
print(i*j, end='\t')
print()
mul = int(input("Enter the number you want the table for :"))
print_multiplication_table(mul)
Output:
Enter the number you want the table for :10
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
No comments:
Post a Comment
Please do not any spam in the comment box.