Chapter 6
Chapter 6 - Python Fundamentals
[Solutions for the book "Cs with Python"
by Sumita Arora for class 11]
Page 174
Q1) Write a program that generates the following output :5
10
9
Solution :
a=5
print a
print a*2
print (a*2)-1
Q2) Write a Python program that accepts radius of a circle and prints its area.
Solution :
#takes radius and prints area
a=input("Enter radius ")
res=3.14*(a**2)
print "Area of circle is :",res
Q3) Write a python program that accepts marks in 5 subjects and outputs average marks.
Solution :
a=input("Enter Marks of subject 1 ")
b=input("Enter Marks of subject 2 ")
c=input("Enter Marks of subject 3 ")
d=input("Enter Marks of subject 4 ")
e=input("Enter Marks of subject 5 ")
avg=(a+b+c+d+e)/2
print "Average marks : ",avg
Q4) Write a short program that asks for your height in centimeters and then converts your height to feet and inches.
Solution :
a=input("Enter your height in centimeters ")
inch= a/2.54
foot= inch/12
print "Your height in inches is :",inch,"in foot :",foot
Q5) Write a program to read a no. n and print n², n³ and n⁴.
Solution :
n=input("Enter any number :")
print n,n**2,n**3,n**4
Q6) Write a program to find area of a triangle.
Solution :
h=input("Enter height of the triangle : ")
b=input("Enter length of base of triangle :")
area= 0.5*b*h
print "Area of the triangle is :",area
Q7) Write a program to compute simple interest and compound interest .
Solution :
#For Simple Interest
p=input("Enter Principal amount ")
r=input("Enter rate ")
t=input("Enter time (in years) ")
si=(p*r*t)/100
print "Simple interest is : ",si
#For Compound Interest
p=input("Enter Principal amount ")
r=input("Enter rate ")
t=input("Enter time ")
n=input("Enter no. of times it is compounded ")
q=n*t
A=(p*(1+(r/n)))**q
print "Compound interest is : ",A
Q8) Write a program to input a number and print its first five multiples.
Solution :
n=input("Enter the no. to calculate multiples ")
print n*1 #Can also be done using range but this chapter teaches python fundamentals.
print n*2
print n*3
print n*4
print n*5
Q9) Write a program to read details like name, class, age of a student and then print the details firstly in same line and then in separate lines.
Have 2 blank lines in these 2 different types of prints.
Solution :
n=raw_input("Enter name ")
c=raw_input("Enter Class ")
a=input("Enter age ")
print n,c,a
print
print
print n
print c
print a
Q10) Write a program to read three numbers in three variables and swap first to variables with the sums of first and second, second and third numbers respectively.
Solution :
a=input("Enter any no. ")
b=input("Enter another no. ")
c=input("Enter another number ")
a=a+b
b=b+c
print a,b,c
Solution :
a=input("Enter Marks of subject 1 ")
b=input("Enter Marks of subject 2 ")
c=input("Enter Marks of subject 3 ")
d=input("Enter Marks of subject 4 ")
e=input("Enter Marks of subject 5 ")
avg=(a+b+c+d+e)/2
print "Average marks : ",avg
Q4) Write a short program that asks for your height in centimeters and then converts your height to feet and inches.
Solution :
a=input("Enter your height in centimeters ")
inch= a/2.54
foot= inch/12
print "Your height in inches is :",inch,"in foot :",foot
Q5) Write a program to read a no. n and print n², n³ and n⁴.
Solution :
n=input("Enter any number :")
print n,n**2,n**3,n**4
Q6) Write a program to find area of a triangle.
Solution :
h=input("Enter height of the triangle : ")
b=input("Enter length of base of triangle :")
area= 0.5*b*h
print "Area of the triangle is :",area
Q7) Write a program to compute simple interest and compound interest .
Using above formula for compound interest |
Solution :
#For Simple Interest
p=input("Enter Principal amount ")
r=input("Enter rate ")
t=input("Enter time (in years) ")
si=(p*r*t)/100
print "Simple interest is : ",si
#For Compound Interest
p=input("Enter Principal amount ")
r=input("Enter rate ")
t=input("Enter time ")
n=input("Enter no. of times it is compounded ")
q=n*t
A=(p*(1+(r/n)))**q
print "Compound interest is : ",A
Q8) Write a program to input a number and print its first five multiples.
Solution :
n=input("Enter the no. to calculate multiples ")
print n*1 #Can also be done using range but this chapter teaches python fundamentals.
print n*2
print n*3
print n*4
print n*5
Q9) Write a program to read details like name, class, age of a student and then print the details firstly in same line and then in separate lines.
Have 2 blank lines in these 2 different types of prints.
Solution :
n=raw_input("Enter name ")
c=raw_input("Enter Class ")
a=input("Enter age ")
print n,c,a
print n
print c
print a
Q10) Write a program to read three numbers in three variables and swap first to variables with the sums of first and second, second and third numbers respectively.
Solution :
a=input("Enter any no. ")
b=input("Enter another no. ")
c=input("Enter another number ")
a=a+b
b=b+c
print a,b,c
---- END ----
please upload chapter 5 flow of control.
ReplyDeleteI really appreciate the information shared above. It’s of great help. If someone wants to learn Online (Virtual) instructor lead live training in #APACHE#CAMEL, kindly contact us http://www.maxmunus.com/contact
ReplyDeleteMaxMunus Offer World Class Virtual Instructor-led training on #APACHE #CAMEL. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ pieces of training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
Avishek Priyadarshi
MaxMunus
E-mail: avishek@maxmunus.com
Skype id: avishek_2.
Ph:(0) 8553177744 / 080 - 41103383
http://www.maxmunus.com/
this is not a Sumita Arora Python book of class 11
ReplyDeleteyes I also agree....
DeleteI think u have some confusion bcoz this is Sumita Arora Python book of class 11
Deletemost of your codes are wrong(ex. the compound interest one) and neither your codes are complete nor they are aligned with the book
ReplyDeleteP=input("Principle=")
DeleteP=eval(P)
R=input("Rate of interest=")
R=eval(R)
T=input("time period=")
T=eval(T)
I=P*R*T
print("simple Interest= ",I)
n=input("compounding per period=")
n=eval(n)
A= int(P(1+(R/n))**(n*t)
print("compound interest=",A)
I think this is the correct coding of simple and compound interest question
eval() not introduced yet in this chapter
DeleteIt's really helpful
ReplyDelete