def main():
print("The itsy bitsy spider climbed up the waterspout.")
print("Down came the rain and washed the spider out.")
print("Out came the sun and dried up all the rain.")
print("The itsy bitsy spider climbed up the waterspout.")
print()
print("The big hairy spider climbed up the waterspout.")
print("Down came the rain and washed the spider out.")
print("Out came the sun and dried up all the rain.")
print("The big hairy spider climbed up the waterspout.")
print()
print("The teeny tiny spider climbed up the waterspout.")
print("Down came the rain and washed the spider out.")
print("Out came the sun and dried up all the rain.")
print("The teeny tiny spider climbed up the waterspout.")
print()
main()
Short Project 2
Print lyrics
In this short project you will write a program that prints the lyrics for the nursery rhyme The Itsy Bitsy Spider. Here is the lyrics:
The itsy bitsy spider climbed up the waterspout. Down came the rain and washed the spider out. Out came the sun and dried up all the rain. The itsy bitsy spider climbed up the waterspout. The big hairy spider climbed up the waterspout. Down came the rain and washed the spider out. Out came the sun and dried up all the rain. The big hairy spider climbed up the waterspout. The teeny tiny spider climbed up the waterspout. Down came the rain and washed the spider out. Out came the sun and dried up all the rain. The teeny tiny spider climbed up the waterspout.
Name the program spider.py
. Make sure that gradescope gives you the points for passing the test cases.
A bad solution
Development strategy
Each paragraph mentions one spider. This lyrics includes three types of spiders: "itsy bitsy"
, "big hairy"
, and "teeny tiny"
. You can define your own functions and call your functions within verse
function. Note the verse
function can only take one of the three arguments (e.g., "big hairy"
).
# All your functions are defined here
def verse(spider_type):
# write your code here
if __name__ == '__main__':
"itsy bitsy")
verse("big hairy")
verse("teeny tiny") verse(
This section gives you a quick recap of what we covered in class or introduces any new tips or examples that might help you complete the assignment. Take a few minutes to read through it before you begin.
Writing a function
- Start with
def
followed by the name of the function - Add parameters inside the parentheses in the function definition
- Print a string within the function without return
def print_greeting(name):
print("Hello " + name + "!")
def main():
"Mickey")
print_greeting("Minnie")
print_greeting(
main()
Hello Mickey!
Hello Minnie!
Using format()
= 20
age = 'Philip' name
Here’s how we can do concatenation using the +
operator:
+ ' is ' + str(age) + ' years old' name
'Philip is 20 years old'
We can do the same with the .format()
method, using {}
as place holders for our variables:
'{} is {} years old'.format(name, age)
'Philip is 20 years old'