You are on page 1of 5

A Solution Manual

To

A Practical Introduction to Python Programming

[Brian Heinold,
Department of Mathematics and Computer Science
Mount St. Mary’s University]

Engr. Reyhan Usman Dalhatu


Chapter 1
Getting Started

# 1: Printing a rectangle

print ('*' * 19) #print * 19x


print ('*' * 19)
print ('*' * 19)
print ('*' * 19)

#2: Printing a rectangle

print ('*' * 19)


print ('* *') #prints * 2x with space in-between
print ('* *')
print ('*' * 19)

#3: Printing a triangle

print ('*')
print ('*' * 2)
print ('*' * 3)
print ('*' * 4)

#4: Simple computation

print ((512 - 282)/(47.48 + 5))


#5: Printing the square of a number

num = eval(input("Enter a number: "))


print ("The square of", num, "is", num * num, '.', sep=' ')

#6: Multiplication sequence

x = eval(input("Enter a number: "))


print (x, 2*x, 3*x, 4*x, 5*x, sep='---') #print out x, 2x, 3x, 4x and 5x

#7: Kilogram to Pound converter

weight = eval(input('Enter a weight in kg: '))


print('That is', weight * 2.2, 'pounds.') #for every kg there is 2.2 pounds

#8: Total and Average variable

x = eval(input("Enter a value x: "))


y = eval(input("Enter a value y: "))
z = eval(input("Enter a value z: "))
total = x + y + z #variable that sums xyz
average = total / 3 #average variable
print("Total x, y, z is: ", total)
print("Average: ", average)
print ()
#9: Tip calculator

meal_price = eval(input("Meal price: $"))


tip_percent = eval(input("Tip percentage(%) you want to leave: "))
tip_amount = (tip_percent / 100) * (meal_price)
total_bill = (tip_amount) + (meal_price)
print ("Your meal is: $", meal_price, " and you tipped ", tip_percent, "%
at: $", tip_amount, ".", sep = '')
print ("Your total bill is: $", total_bill, sep = '')

You might also like