Instructor Solutions Manual
TABLE OF CONTENTS
Chapter 1 9
1.1 9
Favorite song. 9
1.2 9
Frost poem. 9
1.2 9
Name and likes. 9
1.3 10
Final score. 10
1.4 10
Punctuation. 10
1.4 10
Name length. 10
1.5 11
Values and types. 11
1.5 11
Meters to feet. 11
1.6 11
Three errors. 11
1.6 12
Wrong symbols. 12
1.7 12
Whose birthday. 12
1.7 12
Gravity calculation. 12
1.9 13
Fun facts. 13
1.9 14
Mad lib. 14
Chapter 2 14
2.2 14
Grade average. 14
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
2
,Introduction to Python Programming
2.2 15
Cups of water. 15
2.2 15
Product as float. 15
2.3 15
After the point. 15
2.3 16
Print n times. 16
2.4 16
Inaccurate tips. 16
2.4 16
Area of a triangle. 16
2.5 17
Change machine. 17
2.5 17
Arrival time. 17
2.6 18
Quadratic formula. 18
2.6 18
Cylinder formulas. 18
2.7 19
Five quotes. 19
2.7 19
Spaced out. 19
2.9 20
Baking bread. 20
2.9 21
Tip calculator. 21
Chapter 3 21
3.1 21
Shift cipher. 21
3.1 22
Hopper quote. 22
3.2 22
Mad lib (f-string). 22
3.2 22
Wage calculator. 22
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
3
,Introduction to Python Programming
3.4 23
List basics. 23
3.5 23
Creating a tuple with user input. 23
3.5 24
Creating a tuple from a list. 24
Chapter 4 24
4.1 24
Programming practice: Friday boolean. 24
4.1 24
Programming practice: Even numbers. 24
4.2 25
Improved division. 25
4.2 25
Converting temperature units. 25
4.3 25
Speed limits. 25
4.5 26
Crochet hook size conversion. 26
4.5 26
Color wavelengths. 26
4.6 27
Programming practice: Meal orders. 27
4.7 28
Ping values. 28
Chapter 5 28
5.1 28
Reading inputs in a while loop. 28
5.1 28
Sum of odd numbers. 28
5.2 29
Counting spaces. 29
5.2 29
Sequences. 29
5.3 30
Printing a triangle of numbers. 30
5.3 30
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
4
,Introduction to Python Programming
Printing two triangles. 30
5.4 31
Using break control statement in a loop. 31
5.4 31
Using a continue statement in a loop. 31
5.5 32
Sum of values less than 10. 32
5.6 32
Prime numbers. 32
Chapter 6 33
6.1 33
Cinema concession stand. 33
6.1 33
Terms and conditions prompt. 33
6.2 34
Laundromat information. 34
6.2 34
Updated terms and conditions prompt. 34
6.3 35
Battle royale game launch. 35
6.4 35
Printing right triangle area. 35
6.4 36
Curving scores. 36
6.5 36
Averaging lists. 36
6.5 37
Estimated days alive. 37
6.6 37
Stream donations. 37
Chapter 7 37
7.1 37
Conversion module. 37
7.1 38
European vacation. 38
7.2 38
Missing imports. 38
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
5
,Introduction to Python Programming
7.2 39
Party favors. 39
7.3 40
Conversion test. 40
7.3 41
Side effects. 41
7.5 42
Happy birthday. 42
Chapter 8 43
8.1 43
Number of characters in the string. 43
8.1 43
What is my character? 43
8.2 44
Changing the greeting message. 44
8.2 44
Editing the string at specified locations. 44
8.3 44
Finding all spaces. 44
8.4 45
Formatting a list of numbers. 45
8.5 45
Unique and comma-separated words. 45
8.5 45
Lunch order. 45
Chapter 9 46
9.1 46
Simple Searching. 46
9.1 46
More complex searching. 46
9.1 47
Sports list. 47
9.2 47
Sorting and reversing. 47
9.3 48
Copy. 48
9.4 48
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
6
,Introduction to Python Programming
Matrix multiplication. 48
9.5 49
Selecting 5 letter words. 49
9.5 49
Books starting with 'A'. 49
Chapter 10 50
10.1 50
Investigate variable types. 50
10.2 50
Personal information dictionary. 50
10.3 50
The number of unique characters. 50
10.3 51
Create a dictionary of cars step-by-step. 51
10.4 51
Character count in a string. 51
10.4 52
Calculate the total number of fruits. 52
10.5 52
Product prices. 52
10.5 52
Restructuring the company data. 52
10.6 53
Even and odd values. 53
Chapter 11 54
11.2 54
Creating a class for an airline's flight tickets. 54
11.2 55
Creating a class for fantasy books. 55
11.3 55
Creating a class for vending machines. 55
11.4 56
Expanding the Account class. 56
11.4 57
Combining exercise logs. 57
11.5 58
Missing import statement. 58
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
7
,Introduction to Python Programming
11.5 59
Missing class import statement. 59
Chapter 12 59
12.2 59
Recursive summation. 59
12.2 60
Digits. 60
12.3 60
Remove duplicates. 60
12.4 61
Recursive power. 61
12.4 61
Recursive power (with any integer power). 61
12.5 62
Coin combinations. 62
12.5 62
Generate random coin toss. 62
Chapter 13 63
13.1 63
Employee and Developer classes. 63
13.1 63
Polygon classes. 63
13.2 64
Creating a subclass with an instance attribute. 64
13.3 65
Using super(). 65
13.3 65
Overriding methods. 65
13.4 66
Overriding methods. 66
13.5 66
Fixing the diamond problem with a mixin class. 66
Chapter 14 67
14.1 67
Reading from a file. 67
14.1 67
Reading from a file line by line. 67
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
8
,Introduction to Python Programming
14.2 68
Writing to a new file. 68
14.2 69
Writing to an existing file. 69
14.3 69
Processing a CSV file. 69
14.4 70
United countries. 70
14.4 70
Type analyzer. 70
14.5 71
Language objects. 71
14.5 72
Looking up keys. 72
Chapter 1
1.1
Favorite song.
print("Hello! What is your name?")
name = input()
print("Nice to meet you, " + name + ".")
print("What is your favorite song?")
song = input()
print("Cool! I like", song, "too.")
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
9
, Introduction to Python Programming
1.2
Frost poem.
print("I shall be telling this with a sigh")
print("Somewhere ages and ages hence:")
print("Two roads diverged in a wood, and I--")
print("I took the one less traveled by,")
print("And that has made all the difference.")
1.2
Name and likes.
name = input("What is your name? ")
like = input("What do you like? ")
print()
print(name, "likes", like)
1.3
Final score.
team1 = "Liverpool"
score1 = 4
team2 = "Chelsea"
score2 = 3
print(team1, "versus", team2)
print("Final score:", score1, "to", score2)
For more free, peer-reviewed, openly licensed resources visit OpenStax.org.
10