Python Assignment
Python Assignment
1
print(sub)
print(prod)
print(div)
print(mod)
[3]: #Write a program to calculate the average of two numbers. Print their deviation
a=int(input("Enter the value of a:"))
b=int(input("Eneter the value of b:"))
avg=a+b
dev1=a-avg
dev2=b-avg
print("the average is",avg)
2
print("The deviation of the first number",dev1)
print("The deviation of the second number",dev2)
[4]: #A car starts from a stoplight and is traveling with a velocity of 10 m/sec␣
↪east in 20 seconds. Write a program to find the acceleration of the car.␣
↪(acc = (vfinal−vintial)/time).
Enter a number:4
It is a even number!
3
[7]: # Surface area of a prism can be calculated if the lengths of the three sides␣
↪are known. Write a program that takes the sides as input (read it as␣
↪integer) and prints the surface area of the prism (Surface Area = 2ab + 2bc␣
↪+ 2ca).
examination = 50 percent.'''
exam1 = float(input("Enter marks for the first examination (out of 100): "))
exam2 = float(input("Enter marks for the second examination (out of 100): "))
sports = float(input("Enter marks for the sports event (out of 50): "))
activity1 = float(input("Enter marks for the first activity (out of 20): "))
activity2 = float(input("Enter marks for the second activity (out of 20): "))
activity3 = float(input("Enter marks for the third activity (out of 20): "))
exam_total = (exam1 + exam2) * 0.5
activity_total = (activity1 + activity2 + activity3) * 0.3
sports_total = sports * 0.2
final_result = exam_total + activity_total + sports_total
[1]: #Write a program to calculate the bill amount for an item given its quantity␣
↪sold, value, discount, and tax
4
Enter basic pay:4555
Total salary: 5238.25
[10]: #Write a program to enter a number and display its hex and octal equivalent and␣
↪its square root.
import math
num=int(input("Enter the number:"))
h=hex(num)
o=oct(num)
sqr=math.sqrt(num)
print("The hexadecimal and octal equivalent of the number is",h,o)
print("The square root of the number is:",sqr)
[11]: '''You need to empty out the rectangular swimming pool which is 12 meters long,␣
↪7
meters wide and 2 meter depth. You have a pump which can move 17 cubic meters␣
↪of water in an
hour. Write a program to find how long it will take to empty your pool? (Volume␣
↪= l * w * h, and flow
= volume/time)'''
l=int(input("Enter the length of the pool:"))
b=int(input("Enter the breadth of the pool:"))
h=int(input("Enter the height of the pool:"))
volume=l*b*h
time=int(input("Enter the time:"))
flow_rate=volume/time
print("The time taken to empty the pool is:",flow_rate)
[13]: #Write a program to calculate the total money in the piggybank given the coins␣
↪of Rs 10, Rs 5, Rs 2 and Rs 1.
5
Enter the number of Rs 2 coins:3
Enter the number of Rs 1 coins:2
Total money in the piggy bank: 78
[15]: # Write a program to calculate the bill amount for an item given its quantity␣
↪sold,
[4]: #Write a program to read and print values of different data types.
integer_value=int(input("Enter an integer:"))
float_value=float(input("Enter a floating-point number:"))
string_value=input("Enter a string:")
boolean_value=input("Enter a boolean value(True/False):")
print("Integer value:",integer_value)
print("Float value:",float_value)
print("String value:",string_value)
print("Boolean value:",boolean_value)
Enter an integer:56
Enter a floating-point number:45.44
Enter a string:hello
Enter a boolean value(True/False):True
Integer value: 56
Float value: 45.44
String value: hello
Boolean value: True
[3]: ''' Write a program to prepare a grocery bill. For that enter the name of the␣
↪items
purchased, quantity in which it is purchased, and its price per unit. Then␣
↪display the bill in the
following format.'''
6
num_items = int(input("Enter the number of items purchased: "))
items=[]
for i in range(num_items):
item_name = input("Enter the name of item {i + 1}:")
item_quantity = int(input("Enter the quantity of {item_name}:"))
item_price = float(input("Enter the price per unit of {item_name}:"))
items.append((item_name,item_quantity,item_price))
print("\n************************ BILL **************************")
print("{'Item Name':<20}{'Item Quantity':<20}{'Item Price':<20}")
print("*********************************************************")
total_amount = 0
for item_name,item_quantity,item_price in items:
total_item_price = item_quantity * item_price
total_amount += total_item_price
print("{item_name:<20}{item_quantity:<20}{total_item_price:<20}")
print("*********************************************************")
print("Total Amount to be paid:",total_amount)
print("*********************************************************")
[ ]:
[ ]: