10/5/22, 5:40 PM unit1 - Jupyter Notebook
# WPP to add 2 number with user input
# demonstrate calculator
In [17]:
number_first=int(input("Enter first number:"))
number_second=int(input("Enter second number:"))
print("Addition of two number is ",number_first+number_second)
print("Substraction of two number is",number_first-number_second)
print("Divison of two number is",float(number_first/number_second))
print("multipication of two number is",number_first*number_second)
print("power number_second of number_first is",number_first**number_second)
Enter first number:10
Enter second number:5
Addition of two number is 15
Substraction of two number is 5
Divison of two number is 2.0
multipication of two number is 50
power number_second of number_first is 100000
# WPP to find area of triangle
In [5]:
base=float(input("Enter the base value:"))
height=float(input("Enter the height value:"))
print("area of triangle is", 1/2*base*height)
Enter the base value:5.5
Enter the height value:7.2
area of triangle is 19.8
In [6]:
#wpp to find area of triangle using Heron's formula
side1=float(input("Enter first side length:"))
side2=float(input("Enter second side length:"))
side3=float(input("Enter third side length:"))
s=(side1+side2+side3)/2
area=(s*(s-side1)*(s-side2)*(s-side3))**0.5
print("area of triangle is", area)
Enter first side length:12
Enter second side length:18
Enter third side length:10
area of triangle is 56.568542494923804
# WPP to find area of circle
In [7]:
print("area of circle:",3.14*(rad**2))
Enter the radius of circle:5
area of circle: 78.5
localhost:8888/notebooks/unit1.py 1/5
10/5/22, 5:40 PM unit1 - Jupyter Notebook
# WPP to find area of trapezoidal
In [8]:
small_side=float(input("enter small side of trapezoidal:"))
big_side=float(input("enter big side of trapezoidal:"))
height=float(input("enter height of trapezoidal:"))
print("area of trapezoidal:",0.5*(small_side+big_side)*height)
enter small side of trapezoidal:10
enter big side of trapezoidal:8
enter height of trapezoidal:5
area of trapezoidal: 45.0
# WPP to find area and volume of cylinder
In [9]:
rad=float(input("Enter the radius of cylinder:"))
height=float(input("enter height of cylinder:"))
print("area of cylinder is",2*3.14*rad*(height+rad))
print("volume of cylinder is",3.14*(rad**2)*height)
Enter the radius of cylinder:10
enter height of cylinder:10
area of cylinder is 1256.0
volume of cylinder is 3140.0
# WPP to convert Fahrenheit to Celsius formula vice
versa
In [11]:
f=float(input("enter the temprature in Fahrebheit:"))
c=float(input("enter the temprature in celsius:"))
print("convert Fahrenheit to Celsius:c=",(f-32)*5/9)
print("convert Celsius to Fahrenheit:f=",(c*9/5)+32)
enter the temprature in Fahrebheit:98.6
enter the temprature in celsius:37.3
convert Fahrenheit to Celsius:c= 37.0
convert Celsius to Fahrenheit:f= 99.14
# #WPP to convert degree to radian vice versa
localhost:8888/notebooks/unit1.py 2/5
10/5/22, 5:40 PM unit1 - Jupyter Notebook
In [15]:
import math
deg=float(input("enter the angle in degree:"))
rad=float(input("enter the angle in radian:"))
print("convert degree to radian:rad=",deg*math.pi/180)
print("convert radian to degree:deg=",rad/math.pi*180)
enter the angle in degree:30
enter the angle in radian:210
convert degree to radian:rad= 0.5235987755982988
convert radian to degree:deg= 12032.113697747287
# WPP to convert days in year,month and days
In [20]:
days=int(input("enter the number of days:"))
year=days//365
month=(days-year*365)//30
day=(days-year*365-month*30)
print("days={} year:{} month:{} day:{}".format(days,year,month,day))
enter the number of days:1001
days=1001 year:2 month:9 day:1
# WPP to convert sec in minute,sec and hour
In [24]:
secs=int(input("enter the second:"))
hour=secs//3600
minu =(secs-hour*3600)//60
sec=secs-hour*3600-minu*60
print("secs={} to hour:{} min:{} sec:{}".format(secs,hour,minu,sec))
enter the second:150005
secs=150005 to hour:41 min:40 sec:5
# WPP to convert number to binary,hex and octal
In [25]:
Number=int(input("enter number:"))
print("binary number:",bin(Number))
print("hex number:",hex(Number))
print("oct number:",oct(Number))
enter number:11
binary number: 0b1011
hex number: 0xb
oct number: 0o13
# WPP to calculate the distance between two points
localhost:8888/notebooks/unit1.py 3/5
10/5/22, 5:40 PM unit1 - Jupyter Notebook
In [37]:
x1=int(input("enter x cordinate of first point:"))
y1=int(input("enter y cordinate of first point:"))
x2=int(input("enter x cordinate of second point:"))
y2=int(input("enter y cordinate of second point:"))
distance=((x1-x2)**2+(y1-y2)**2)**0.5
print("distance=",format(distance,".2f"))
enter x cordinate of first point:5
enter y cordinate of first point:4
enter x cordinate of second point:2
enter y cordinate of second point:3
distance= 3.16
# WPP demonstrates the use of relation operators
In [40]:
x=int(input("enter number:"))
y=int(input("enter number:"))
print("x<y",x<y)
print("x<=y",x<=y)
print("x>y",x>y)
print("x>=y",x>=y)
print("x==y",x==y)
print("x!=y",x!=y)
enter number:10
enter number:20
x<y True
x<=y True
x>y False
x>=y False
x==y False
x!=y True
# WPP to calculate avg of two number and their
devitation
In [44]:
first=int(input("enter number"))
second=int(input("enter number"))
avg=(first+second)/2
dev1=first-avg
dev2=second-avg
print("avg is{} devitation of first{} devitation of second{}".format(avg,dev1,dev2))
enter number10
enter number20
avg is15.0 devitation of first-5.0 devitation of second5.0
# WPP to total amount of money in the piggybank, given
the coins of rs 10,rs 5, rs 2 and rs1
localhost:8888/notebooks/unit1.py 4/5
10/5/22, 5:40 PM unit1 - Jupyter Notebook
In [45]:
num_of_10_coins=int(input("enter the number of 10rs coins in piggybank:"))
num_of_5_coins=int(input("enter the number of 5rs coins in piggybank:"))
num_of_2_coins=int(input("enter the number of 2rs coins in piggybank:"))
num_of_1_coins=int(input("enter the number of 1rs coins in piggybank:"))
print("total amount in piggybank=",num_of_10_coins*10+num_of_5_coins*5+num_of_2_coins*2+num
enter the number of 10rs coins in piggybank:10
enter the number of 5rs coins in piggybank:20
enter the number of 2rs coins in piggybank:10
enter the number of 1rs coins in piggybank:10
total amount in piggybank= 230
# WPP to calculate the bill amount for an item given its
quantity sold,value,discount,and tax
In [47]:
qty=float(input("enter the quantity of item sold:"))
val=float(input("enter the value of item:"))
discount=float(input("enter the discount percentage:"))
tax=float(input("enter the tax:"))
amt=qty*val
discount_amt=(amt*discount)/100
sub_total=amt-discount_amt
tax_amt=(sub_total*tax)/100
total_amt=sub_total+tax_amt
print("******************************************")
print("Quantity sold: \t",qty)
print("Price per item: \t",val)
print(" \t \t --------------")
print("Discount total: \t-",sub_total)
print("tax: \t\t\t+",tax_amt)
print(" \t \t --------------")
print("total amount to be paid:",total_amt)
enter the quantity of item sold:80
enter the value of item:100
enter the discount percentage:10
enter the tax:14
******************************************
Quantity sold: 80.0
Price per item: 100.0
--------------
Discount total: - 7200.0
tax: + 1008.0
--------------
total amount to be paid: 8208.0
localhost:8888/notebooks/unit1.py 5/5