A Practical Introduction to Python Programming (Brian Heinold Department of Mathematics and Computer Science Mount St. Mary’s University)
Solution Manual
Engr. Hassan Mehmood Khan
Ver2.0
Date: 9/12/2017
Chapter 1 Exercise Q:6 Solution
x=eval(input('Enter the number: ')) y=2*x y2=3*x y3=4*x y4=5*x print(x,y,y2,y3,y4,sep='---')
Q:7 Solution
x=eval(input('Enter the Weight in Kg: ')) y=x*2.2 print('The weight in Pounds is: ', y)
Q:8 Solution
y=eval(input('Enter the Price of the meal: ')) y1=eval(input('Enter the %age of tip you want to leave: ')) tip=y*(y1/100) bill=y+tip print('The amount of bill is',bill,'and the tip is',tip)
Ver2.0
Date: 9/12/2017
Chapter 2 Exercise Q:1 Solution
for i in range(100): print('Your Name')
Q:2 Solution
for i in range(200): print('Your Name',end=' ')
Q:3 Solution
for i in range(100): print(i+1,'Your Name')
Q:4 Solution
for i in range(20): range(20): y=i+1 print(y,y*y)
Q:5 Solution
for i in range(8,90,3):
Ver2.0
Date: 9/12/2017
print(i)
Q:6 Solution
for i in range(100,1,-2): print(i)
Q:7 Solution
for i in range(10): range(10): print('A',end='') for j in range(7): range(7): print('B',end='') for k in range(4): print('CD',end='') print('E',end='') for l in range(6): range(6): print('F',end='') print('G',end='')
Q:8 Solution
y=input('Enter y=input('Enter Your Name: ') z=eval(input('Enter the # of times you want to print your Name: ')) for i in range(z): print(y)
Ver2.0
Date: 9/12/2017
Q:9 Solution
d=eval(input('How many Fibinacci Numbers you want to print: ')) a=1 b=1 for i in range(d): range(d): a1 = a b1 = b a = b1 b = a1 + b1 print(a1,end=' ')
Q:10 Solution
z=eval(input('Specify the width of stars in #:')) r=eval(input('Specify the height of stars in #: '))
for i in range(r): range(r): print ('*'*z)
Q:11 Solution
a=eval(input('Provide the height of the box: ')) b=eval(input('Provide the width of the box: ')) d=a-2 r=b-2
Ver2.0
Date: 9/12/2017
if a >= 1: print('*'*b) if a > 1: for i in range(d): print('*',end='') for i in range(r): print(' ',end='') print('*') print('*'*b,end='')
Q:12 Solution
r=eval(input('Specify the height of stars in #: '))
for i in range(r): range(r): print('*'*(i+1))
Q:13 Solution
r=eval(input('Specify the height of stars in #: '))
for i in range(r,0,-1): print('*'*i)
Ver2.0
Date: 9/12/2017