-
Notifications
You must be signed in to change notification settings - Fork 35
/
Exercises_Ch_006.py
122 lines (78 loc) · 1.82 KB
/
Exercises_Ch_006.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# "Python Programming: An Introduction to Computer Science, Third Edition" by John Zelle
# Chapter 6: Defining Functions
# End-of-Chapter Exercises
# REVIEW QUESTIONS
# True/False
# 1. F
# 2. F
# 3. T
# 4. T
# 5. F
# 6. F
# 7. Python functions can never modify parameters. FALSE
# [Note: This is true of OOP languages in general, I think, as opposed to functional programming languages.
# Explanation: p.193: "In some cases, functions can also communicate back to the calling program by making
# changes to the function parameters."]
# 8. T
# 9. R
# 10. F
# Multiple Choice
# 1. B
# 2. A
# 3. A
# 4. B
# 5. D
# 6. A
# 7. D
# 8. A
# 9. D
# 10. A
# Discussion
# 1. In your own words, describe the two motivations for defining functions in your programs.
# 2.
# 3.
#
# 4.
#
# 5.
# PROGRAMMING EXERCISES
# 1.
#
def refrain():
print("Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!")
def animal(kind, noise):
refrain()
print("And on that farm he had a " kind "Ee-igh, Ee-igh, Oh!")
print("With a " noise", " noise " here and a " noise", " noise " there.")
print("Here a " noise ", there a " noise ", everywhere a " noise ".")
refrain()
def main:
animal("pig", "oink")
print()
animal("duck", "quack")
print()
animal("sheep", "baah")
print()
animal("cow", "moo")
print()
animal("dog", "woof")
# 2. Write a program to print the lyrics for ten verses of "The Ants Go Marching." A couple of sample versus are given below.
# You may choose your own activity for the "little one" in each verse, but be sure to choose something that makes the rhyme
# work (or almost work).
# 3. Write definitions for these functions:
# 4.
# 5.
# 6.
# 7.
# 8.
# 9.
# 10.
# 11.
# 12.
# 13.
# 14.
# 15.
# 16.
# 17.
# 9.
#10.