1.
Program to calculate the simple Interest
based on given input by user
In [1]: # Program to calculate the simple Interest
P = int(input("Principal="))
R = int(input("Rate of Interest="))
T=int(input("Time="))
SimpleInterest=(P*R*T)/100
print("Simple Interest is:",SimpleInterest)
Principal=2000
Rate of Interest=10
Time=3
Simple Interest is: 600.0
2. Write a program to obtain three numbers
and print their sum?
In [2]: print("Please enter three numbers to get their sum")
num1 = int (input("Enter number 1:"))
num2 = int (input("Enter number 2:"))
num3 = int (input("Enter number 3:"))
Sum = num1+num2+num3
print(" The sum of ", num1, ",",num2, ",", "and ", num3,"is:",Sum )
Please enter three numbers to get their sum
Enter number 1:23
Enter number 2:34
Enter number 3:45
The sum of 23 , 34 , and 45 is: 102
3. Write a program to calculate the BMI ,
input: weight(kg) and height(m)
In [5]: weight_in_kg = float(input('Enter weight in Kg:'))
height_in_m = float(input('Enter height in m:'))
bmi = weight_in_kg/height_in_m**2
print("Weight: ", weight_in_kg,"kg")
print("Height: ", height_in_m,"m")
print("BMI is:", bmi)
if(bmi <18.5):
print("The person is underweight.")
elif 18.5<=bmi<=24.9:
print("The person is normal.")
elif 25.0<=bmi<=29.9:
print("The person is Over weight.")
elif bmi> 30:
print("The person is Obese.")
Enter weight in Kg:68
Enter height in m:1.55
Weight: 68.0 kg
Height: 1.55 m
BMI is: 28.303850156087407
The person is Over weight.
4. Write a program to print the table upto 10
of a given number, formatted as n x 1 = n, ...
In [8]: # Write a program to print the table upto 10 of a given number, formatted as
print("Program to generate the table of a given number")
num =int(input('Enter a number to generate table: '))
i=1
while i<11:
print(num,' x ', i, ' = ', num*i)
i+=1
Program to generate the table of a given number
Enter a number to generate table: 9
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
9 x 10 = 90
5. program to take numeric input from user
and store it in list and add them.
In [12]: # program to take numeric input from user, store it in list and find sum?
print("Program to find sum of numbers based on user input, enter -1 as last entry as
my_list=[] #generate an empty list
i=0
while i != -1:
my_list.append(int(input())) #enter data to list
i = my_list[-1]
print("Original List:",my_list)
my_list.pop() # remove -1 from the list, so as to add the numbers
print("New List:",my_list)
print(" Sum of numbers in above list : ",sum(my_list))
Program to find sum of numbers based on user input, enter -1 as last entry as last n
umber
2
3
4
45
5657
8
7
89
80
-1
Original List: [2, 3, 4, 45, 5657, 8, 7, 89, 80, -1]
New List: [2, 3, 4, 45, 5657, 8, 7, 89, 80]
Sum of numbers in above list : 5895
6. Write a program to take input from user
using List and find the mean?
In [15]: print("Program to find mean based on user input, enter -1 as last entry")
my_list=[]
i=0
while i != -1:
my_list.append(int(input()))
i = my_list[-1]
my_list.pop()
print("List entered",my_list)
n = len(my_list)
sum1 = sum(my_list)
print("Sum: ",sum1)
mean = sum1 / n
print("Mean :",mean)
Program to find mean based on user input, enter -1 as last entry
23
34
5
6
7
85
23
45
67
-1
List entered [23, 34, 5, 6, 7, 85, 23, 45, 67]
Sum: 295
Mean : 32.77777777777778
7. Program to find Area and perimeter of
rectangle, given length and breadth?
In [ ]: # program to find area and perimeter of rectangle
l = int(input("Enter Length: "))
b = int(input("Enter breadth: "))
area =l*b
perimeter= 2*(l+b)
print("Area of rectangle : ", area)
print("Perimeter of rectangle: ", perimeter)
Enter Length: 32
Enter breadth: 12
Area of rectangle : 384
Perimeter of rectangle: 88
8. Program to Convert temperature in
degree celcius to farenheit and vice versa.
In [ ]: # Program to Convert temperature in degree celcius to farenheit and vice versa.
temp_unit = input("Enter Celsius (C) or Fareneheit(F) for input temperature unit ")
if temp_unit.upper() == 'C':
temp = int(input("Enter Temperature in degree celsius : "))
output = (temp *9/5)+32
print("The temperature is ", output,"Fareheit")
else:
temp = int(input("Enter Temperature in Farenheit : "))
output = (temp -30)/2
print("The temperature is ", output,"Celsius")
Enter Celsius (C) or Fareneheit(F) for input temperature unit c
Enter Temperature in degree celsius : 45
the temperature is 113.0 Fareheit
Enter Celsius (C) or Fareneheit(F) for input temperature unit f
Enter Temperature in Farenheit : 234
The temperature is 102.0 Celsius
9. Program to identify a given number is
even or odd.
In [ ]: # Program to identify a given number is even or odd.
print('Program to identify a given number is even or odd')
num = int(input('Enter a number: '))
if num%2 == 0:
print(num,"is an even number.")
else:
print(num,"is an odd number.")
Program to identify a given number is even or odd
Enter a number: 34
34 is an even number.
Program to identify a given number is even or odd
Enter a number: 23
23 is an odd number
10. Program to find the largest or smallest of
the given three numbers.
In [ ]:
In [ ]: print('To find the largest and smallest of the given number')
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
if num1>num2 and num1>num3:
print(num1,"is the largest number.")
if num2>num3:
print(num3,"is the smallest number.")
else:
print(num2, "is the smallest number.")
elif num2>num3:
print(num2," is the largest number")
if num1>num3:
print(num3,"is the smallest number.")
else:
print(num1, "is the smallest number.")
else:
print(num3,"is the largest number.")
if num1>num2:
print(num2,"is the smallest number.")
else:
print(num1, "is the smallest number.")
To find the largest and smallest of the given number
Enter first number: 56
Enter second number: 35
Enter third number: 23
56 is the largest number.
23 is the smallest number.
runfile('C:/Users/admin/.spyder-py3/temp.py', wdir='C:/Users/admin/.spyder-py3') To find the
largest and smallest of the given number
Enter first number: 867
Enter second number: 657
Enter third number: 23
867 is the largest number.
23 is the smallest number.