Chapter 7
Chapter 7 - Data Handling
[Solutions for the book "Cs with Python"
by Sumita Arora for class 11]
Page 214
Q1) Write a program to obtain principal amount, rate of interest and time from user and compute simple interest.
Solution :
p=input("Enter principal amount")
r=input("Enter rate : ")
t=input("Enter time : ")
si=(p*r*t)/100
print "The simple interest is ",si
p=input("Enter principal amount")
r=input("Enter rate : ")
t=input("Enter time : ")
si=(p*r*t)/100
print "The simple interest is ",si
Q2) Write a program to obtain temperatures of 7 days and then display average temperatures of the week.
Solution :
a=input("Enter temp. for Monday ")
b=input("Enter temp. for Tuesday ")
c=input("Enter temp. for Wednesday ")
d=input("Enter temp. for Thursday ")
e=input("Enter temp. for Friday ")
f=input("Enter temp. for Saturday ")
g=input("Enter temp. for Sunday ")
avg=(a+b+c+d+e+f+g)/2
print "The avg. temp. for the week was ",avg
Q3)Write a program to obtain x,y,z from user and calculate expression : 4x^4+3y^3+9z+6π
Solution :
x=input("Enter value for x ")
y=input("Enter value for y ")
z=input("Enter value for z ")
res=(4*(x**4))+(3(y**3))+(9*z)+6(3.14)
print "Value of the expression is :",res
Q4)Write a program that inputs two numbers a and ab and computes |a-b|/(a+b)
Solution :
a=input("Enter value for a ")
b=input("Enter value for b ")
n=a-b
res=abs(n)/(a+b) #abs here is used to keep a-b positive
Q5)Write a program that reads a number of seconds and prints it in the form: mins and seconds.
Solution :
a=input("Enter in seconds ")
mins=a//60 #as // returns only quotient
secs=a%60 #as % returns only remainder
print "The time in mins and secs is ", mins,"Mins.", secs,"Secs."
Q6)Write a program that reads from user (i) an hour between 1 to 12 and (ii) no.s of hours ahead. The program should then print the time after those many hours.
Solution :
x=input("Enter hour between 1-12 ")
y=input("Enter how many hours ahead? ")
a=x+y
if a>12:
d=a-12
print "Time at that time would be ",d,"O'clock"
else:
print "Time at that time would be ",a,"O'clock"
I am still trying to figure out if we can use a simpler code for the above ques (Q6) If you have any idea/suggestion please submit your code in that form at Home page!
a=input("Enter temp. for Monday ")
b=input("Enter temp. for Tuesday ")
c=input("Enter temp. for Wednesday ")
d=input("Enter temp. for Thursday ")
e=input("Enter temp. for Friday ")
f=input("Enter temp. for Saturday ")
g=input("Enter temp. for Sunday ")
avg=(a+b+c+d+e+f+g)/2
print "The avg. temp. for the week was ",avg
Q3)Write a program to obtain x,y,z from user and calculate expression : 4x^4+3y^3+9z+6π
Solution :
x=input("Enter value for x ")
y=input("Enter value for y ")
z=input("Enter value for z ")
res=(4*(x**4))+(3(y**3))+(9*z)+6(3.14)
print "Value of the expression is :",res
Q4)Write a program that inputs two numbers a and ab and computes |a-b|/(a+b)
Solution :
a=input("Enter value for a ")
b=input("Enter value for b ")
n=a-b
res=abs(n)/(a+b) #abs here is used to keep a-b positive
Q5)Write a program that reads a number of seconds and prints it in the form: mins and seconds.
Solution :
a=input("Enter in seconds ")
mins=a//60 #as // returns only quotient
secs=a%60 #as % returns only remainder
print "The time in mins and secs is ", mins,"Mins.", secs,"Secs."
Q6)Write a program that reads from user (i) an hour between 1 to 12 and (ii) no.s of hours ahead. The program should then print the time after those many hours.
Solution :
x=input("Enter hour between 1-12 ")
y=input("Enter how many hours ahead? ")
a=x+y
if a>12:
d=a-12
print "Time at that time would be ",d,"O'clock"
else:
print "Time at that time would be ",a,"O'clock"
I am still trying to figure out if we can use a simpler code for the above ques (Q6) If you have any idea/suggestion please submit your code in that form at Home page!
----xx----
The solution of the questions in which we have to calculate average temperature is WRONG ... You should divide sum of all the variable by 7 NOT by 2.
ReplyDeleteHope u understand
Thanks for the solution
ReplyDeletethx a lot
ReplyDelete