Python Arithmetic operator examples

Example:8
Write a python script to take input for total distance in inches, convert them into total feet and inches? [ 1 feet = 12 inches ]
Sol:

inh=int(input("Enter total inches "))
f=inh//12
inh=inh%12
print(f," feet ",inh," inches")

Output:

Enter total inches 25
2 feet 1 inches
>>>
Enter total inches 15
1 feet 3 inches
>>>

Example:9
Write a python script to take input for total distance in meters, convert them into km and m? [ 1 km = 1000 m ]
Sol:

m=int(input("Enter total distance in meters "))
km=m//1000
m=m%1000
print(km," km ",m," m")

Output:

Enter total distance in meters 1500
1 km 500 m
>>>
Enter total distance in meters 3500
3 km 500 m
>>>

Example:10
Write a python script to take input for total distance in cm, convert them into m and cm? [ 1 m = 100 cm ]
Sol:

cm=int(input("Enter total distance in cm "))
m=cm//100
cm=cm%100
print(m," m ",cm," cm")

Output:

Enter total distance in cm 125
1 m 25 cm
>>>
Enter total distance in cm 175
1 m 75 cm
>>>

Example:11
Write a python script to take input for total number of days. Further convert it into number of years, months, weeks and days?
Sol:

d=int(input("Enter total days "))
y=d//365
d=d%365
m=d//30
d=d%30
w=d//7
d=d%7
print(y," Year ",m," Month ",w," Week ",d," Days")

Output:

Enter total days 403
1 Year 1 Month 1 Week 1 Days
>>>
Enter total days 366
1 Year 0 Month 0 Week 1 Days
>>>
Enter total days 396
1 Year 1 Month 0 Week 1 Days
>>>
Enter total days 402
1 Year 1 Month 1 Week 0 Days
>>>

Example:12
(ATM) Write a python script to take input for total amount in multiples of 100. convert into into number of 2000, 500, 200 and 100 rupee notes?
Sol:

amt=int(input("Enter total amount (in multiple of 100) "))
a=amt//2000
amt=amt%2000
b=amt//500
amt=amt%500
c=amt//200
amt=amt%200
d=amt//100
print("Rs.2000:",a," Rs.500:",b,"Rs.200:",c,"Rs.100:",d)

Output:

Enter total amount (in multiple of 100) 2800
Rs.2000: 1 Rs.500: 1 Rs.200: 1 Rs.100: 1
>>>
Enter total amount (in multiple of 100) 2900
Rs.2000: 1 Rs.500: 1 Rs.200: 2 Rs.100: 0
>>>

Visitor Counter

0056739