0% found this document useful (0 votes)
15 views

Python Assignment

Uploaded by

R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Python Assignment

Uploaded by

R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PYTHON ASSIGNMENT

August 15, 2024

[1]: #Write a program to calculate the area of a circle.


radius=int(input("Enter the value of radius:"))
area=radius*radius*3.14
print(area)

Enter the value of radius:5


78.5

[3]: # Write a program to perform addition, subtraction, division, and␣


↪multiplication on two floating point numbers

a=float(input("Enter the first value:"))


b=float(input("Enter the second value:"))
add=a+b
sub=a-b
prod=a*b
div=a/b
print(add)
print(sub)
print(prod)
print(div)

Enter the first value:3


Enter the second value:4
7.0
-1.0
12.0
0.75

[4]: #Write a program to perform addition, subtraction, multiplication, division,␣


↪integer division, and modulo division on two integer numbers.

a=int(input("Enter the first value:"))


b=int(input("Enter the second value:"))
add=a+b
sub=a-b
prod=a*b
div=a/b
mod=a%b
print(add)

1
print(sub)
print(prod)
print(div)
print(mod)

Enter the first value:5


Enter the second value:4
9
1
20
1.25
1

[5]: #Write a program to calculate the distance between two points.


import math
x1=int(input("Enter the value of x1:"))
x2=int(input("Enter the value of x2:"))
y1=int(input("Enter the value of y1:"))
y2=int(input("Enter the value of y2:"))
dist=math.sqrt(((x1-x2)**2)+((y1-y2)**2))
print(dist)

Enter the value of x1:3


Enter the value of x2:2
Enter the value of y1:1
Enter the value of y2:5
4.123105625617661

[6]: #Write a program to to calculate area of a triangle using Heron’s formula


import math
a=int(input("Enter the values of a"))
b=int(input("Enter the values of b"))
c=int(input("Enter the values of c"))
s=(a+b+c)/2
area=math.sqrt(s*(s-a)*(s-b)*(s-c))
print(area)

Enter the values of a6


Enter the values of b7
Enter the values of c8
20.33316256758894

[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)

Enter the value of a:45


Eneter the value of b:56
the average is 101
The deviation of the first number -56
The deviation of the second number -45

[7]: #Write a program to convert degrees Fahrenheit into degrees Celsius.


F=int(input("Enter the temperature in Fahrenheit:"))
C=(F-32)*(5/9)
print(C)

Enter the temperature in Fahrenheit:333


167.22222222222223

[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).

v1=int(input("Enter the final velocity of the car:"))


v2=int(input("Enter the intial velocity of the car:"))
t=int(input("Enter the time taken by the car:"))
acc=(v1-v2)/t
print("The acclertion of the car is:",acc)

Enter the final velocity of the car:45


Enter the intial velocity of the car:67
Enter the time taken by the car:43
The acclertion of the car is: -0.5116279069767442

[5]: #Write a program that calculates the number of seconds in a day.


day=int(input("Enter the number of days:"))
time=day*24*60*60
print("The time in seconds as per the number of days is",time)

Enter the number of days:5


The time in seconds as per the number of days is 432000

[6]: #Write a program that demonstrate the use of relational operators


a=int(input("Enter a number:"))
if(a%2==0):
print("It is a even number!")
else:
print("It is a odd number!")

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).

a=int(input("Enter the value of a:"))


b=int(input("Enter the value of b:"))
c=int(input("Enter the value of c:"))
s=(2*a*b)+(2*b*c)+(2*c*a)
print("The surface area of the prism is:",s)

Enter the value of a:5


Enter the value of b:4
Enter the value of c:3
The surface area of the prism is: 94

[2]: '''Write a program to calculate a student’s result based on two examinations, 1␣


↪sports

event, and 3 activities conducted. The weightage of activities = 30 percent,␣


↪sports = 20 percent, and

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

print("Final result:", final_result)

Enter marks for the first examination (out of 100): 45


Enter marks for the second examination (out of 100): 44
Enter marks for the sports event (out of 50): 34
Enter marks for the first activity (out of 20): 56
Enter marks for the second activity (out of 20): 32
Enter marks for the third activity (out of 20): 89
Final result: 104.39999999999999

[1]: #Write a program to calculate the bill amount for an item given its quantity␣
↪sold, value, discount, and tax

basic_pay=float(input("Enter basic pay:"))


hra=basic_pay*0.1
ta=basic_pay*0.05
total_salary=basic_pay+hra+ta
print("Total salary:", total_salary)

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)

Enter the number:34


The hexadecimal and octal equivalent of the number is 0x22 0o42
The square root of the number is: 5.830951894845301

[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)

Enter the length of the pool:12


Enter the breadth of the pool:7
Enter the height of the pool:2
Enter the time:17
The time taken to empty the pool is: 9.882352941176471

[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.

ten_rupee_coins=int(input("Enter the number of Rs 10 coins:"))


five_rupee_coins=int(input("Enter the number of Rs 5 coins:"))
two_rupee_coins=int(input("Enter the number of Rs 2 coins:"))
one_rupee_coins=int(input("Enter the number of Rs 1 coins:"))
total_money=(10*ten_rupee_coins)+(5*five_rupee_coins)+(2*two_rupee_coins)+(1*one_rupee_coins)
print("Total money in the piggy bank:",total_money)

Enter the number of Rs 10 coins:5


Enter the number of Rs 5 coins:4

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,

value, discount, and tax.


quantity=int(input("Enter the quantity sold:"))
value_per_item=float(input("Enter the value per item:"))
discount_percent=float(input("Enter the discount percentage:"))
tax_percent=float(input("Enter the tax percentage:"))
gross_amount=quantity*value_per_item
discount_amount=gross_amount*(discount_percent/100)
net_amount=gross_amount-discount_amount
tax_amount=net_amount*(tax_percent/100)
bill_amount=net_amount+tax_amount
print("Total bill amount: Rs",bill_amount

Enter the quantity sold:5


Enter the value per item:43
Enter the discount percentage:3
Enter the tax percentage:7
Total bill amount: Rs 223.1485

[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("*********************************************************")

Enter the number of items purchased: 2


Enter the name of item {i + 1}:Chocolate
Enter the quantity of {item_name}:4
Enter the price per unit of {item_name}:34
Enter the name of item {i + 1}:Brush
Enter the quantity of {item_name}:3
Enter the price per unit of {item_name}:89

************************ BILL **************************


{'Item Name':<20}{'Item Quantity':<20}{'Item Price':<20}
*********************************************************
{item_name:<20}{item_quantity:<20}{total_item_price:<20}
{item_name:<20}{item_quantity:<20}{total_item_price:<20}
*********************************************************
Total Amount to be paid: 403.0
*********************************************************

[1]: #Write a program to print the digit at one’s place of a number.


num=int(input("Enter a number: "))
ones_place=num%10
print("Digit at one's place:",ones_place)

Enter a number: 456


Digit at one's place: 6

[ ]:

[ ]:

You might also like