30% found this document useful (27 votes)
9K views

A Solution Manual To A Practical Introduction To Python Programming by Brian Heinold

This document provides a solution manual for Chapter 1 of the book "A Practical Introduction to Python Programming" containing 9 code examples that demonstrate basic Python printing, computation, input/output, and calculation functions including printing shapes, simple math operations, number input/output, sequence multiplication, unit conversion, variable totals/averages, and a tip calculator. The code examples cover fundamental Python concepts like strings, arithmetic operators, variables, input/output, and conditionals to solve basic computational problems.

Uploaded by

Reyhan Dalhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
30% found this document useful (27 votes)
9K views

A Solution Manual To A Practical Introduction To Python Programming by Brian Heinold

This document provides a solution manual for Chapter 1 of the book "A Practical Introduction to Python Programming" containing 9 code examples that demonstrate basic Python printing, computation, input/output, and calculation functions including printing shapes, simple math operations, number input/output, sequence multiplication, unit conversion, variable totals/averages, and a tip calculator. The code examples cover fundamental Python concepts like strings, arithmetic operators, variables, input/output, and conditionals to solve basic computational problems.

Uploaded by

Reyhan Dalhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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