Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Py Exercise3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

PROBLEM SOLVING USING PYTHON

ASSIGNMENT-3
1.
A bookstore needs to buy 60 copies of a book from a publisher. Suppose the cover price of a
book is X, but bookstores get a discount of Y%. Shipping costs incurs Z for the first copy and P
for each additional copy. What is the total wholesale cost for 60 copies to be paid by the
bookstore to the publisher?
X=eval(input("Enter cover price of a book "))
Y=eval(input("Enter discount percentage"))
Z=eval(input("Enter shipping cost for the first book "))
P=eval(input("Enter shipping cost for each additional copy "))
cost=(X-(X*Y/100))*60
shipping=Z+(P*59)
whole=cost+shipping
print("Wholesale price of 60 books is ",whole)

output:-
Enter cover price of a book 100
Enter discount percentage12
Enter shipping cost for the first book 15
Enter shipping cost for each additional copy 10
Wholesale price of 60 books is 5885.0

2.
Assume the population of a city consists of X persons of different age groups. X
includes both male and female. Public welfare department wants to find the
average age of male and female. The department can obtain peoples date of
birth from the corporation from which the age can be calculated. (Note: Use
only sequential statements to solve the problem. Consider X to be less than or
equal to 6)

from datetime import *


m=[]
f=[]
x=[]
cur=date.today()
for i in range(1,7):
g=input("Enter male or female M/F").upper()
print(i,end='.')
x1=input("Enter your birthday date as DD-MM-YYYY")
dob=datetime.strptime(x1,'%d-%m-%Y').date()
day=(cur-dob).days
age=day//365
if g=='M':
m.append(age)
elif g=='F':
f.append(age)
avgm=sum(m)/3
avgf=sum(f)/3
avgp=(sum(m)+sum(f))/6
print("Average age of male is",avgm)
print("Average age of female is",avgf)
print("Average age of people is",avgp)

OUPUT:-
Enter male or female M/FM
1.Enter your birthday date as DD-MM-YYYY01-12-2004
Enter male or female M/FM
2.Enter your birthday date as DD-MM-YYYY09-11-2000
Enter male or female M/FM
3.Enter your birthday date as DD-MM-YYYY23-05-1998
Enter male or female M/FF
4.Enter your birthday date as DD-MM-YYYY07-06-2005
Enter male or female M/FF
5.Enter your birthday date as DD-MM-YYYY11-08-2012
Enter male or female M/FF
6.Enter your birthday date as DD-MM-YYYY27-03-2001
Average age of male is 21.666666666666668
Average age of female is 17.0
Average age of people is 19.333333333333332

1. Swapping two numbers


ADDITIONAL
1. Swapping two numbers
a=int(input("Enter a number :"))
b=int(input("Enter another number :"))
a,b=b,a
print(“a=”,a)
print(“b=”,b)
OUTPUT:-

Enter a number :5

Enter another number :3

a= 3

b= 5

2. Temperature conversion from Fahrenheit to Celsius (Hint: Fahrenheit = 9/5 x Celsius + 32)
F=eval(input("Enter the Fahrenheit "))
C=(F-32)*(5/9)
print("The Celsius is" ,C)
OUTPUT:-

Enter the Fahrenheit 98.7

The Celsius is 37.05555555555556

3. Compute radius of a circle for the given area


A=eval(input("Give area of the circle "))
r=(A/3.14)**(1/2)
print("The radius of the given circle is",r)
OUTPUT:-

Give area of the circle 340

The radius of the given circle is 10.405779873564022

4. Write a program to reverse a two-digit number and print its sum


n=int(input("Enter a two digit number "))
n1=str(n)
sum=0
for i in n1[::-1]:
sum=sum+int(i)
print(n1[::-1])
print(sum)
OUTPUT:-

Enter a two digit number 12

21

5. Compute the gross and net salaries of an employee for the given basic pay (BP) based on the
allowances and deductions. Gross pay includes basic and all allowances, Net pay is the difference
between gross pay and deductions. Allowances: DA = 62% of BP HRA = 8% of BP Deductions:
Insurance = Rs. 2000 PF = 12% of BP
DA=BP*62/100
HRA=BP*8/100
Insurance=2000
PF=BP*12/100
Gross_Pay=BP + DA + HRA
Deductions= Insurance + PF
Net_pay=Gross_Pay-Deductions
print("the net pay of the employee is ",Net_pay)
OUTPUT:-

Enter basic pay of employee :60000

the net pay of the employee is 92800.0

6. Read two complex numbers from the user and find their a. sum b. difference c. product
c1=complex(input("Enter a complex number "))
c2=complex(input("Enter another complex number"))
print("sum=",c1+c2)
print("Difference=",c1-c2)
print("Product=",c1*c2)

OUTPUT:-

Enter a complex number 7+4j


Enter another complex number3+8j
sum= (10+12j)
Difference= (4-4j)
Product= (-11+68j)

You might also like