You're doing great! In the previous levels we still faced a small problem. You have learned to repeat lines, but what if you'd want to slightly change the line. For example if you want to sing the song 'if you're happy and you know it'. It would look like this:
If you'd also want the next verse 'stomp your feet', and the next one, and the next one, you'd have to change the code completely.
In this level you'll learn the for
command, which allows you to make a list of actions and repeat the code with another action each time!
Please take a look!
repeat 2 times
print 'if youre happy and you know it clap your hands'
print 'if youre happy and you know it and you really want to show it'
print 'if youre happy and you know it clap your hands'
In this level we learn a new code called for
. With for
you can make a list and use all elements.
for
creates a block, like repeat
and if
so all lines in the block need to start with 4 spaces.
animals = dog, cat, blobfish
for animal in animals
print 'I love ' animal
Finish this code by adding for action in actions
to line 2.
actions = clap your hands, stomp your feet, shout Hurray!
_
repeat 2 times
print 'If youre happy and you know it, ' action
sleep 2
print 'If youre happy and you know it, and you really want to show it'
print 'If youre happy and you know it, ' action
sleep 3
In this level you can make a schedule for the whole week in an easy way!
Add a second chore, such as vacuuming or tidying up, and make sure it is also divided for the whole week.
Extra The program is not fair, you can be unlucky and wash up all week. How could you make the program more fair?
days = Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
names = mom, dad, Emma, Sophie
for day in days
print names at random ' does the dishes on ' day
Is everybody taking too long throwing the dice? In this level you can let Hedy throw all the dice at once! Change the names into names of your friends or family, and finish the code.
players = Ann, John, Jesse
choices = 1, 2, 3, 4, 5, 6
_ _ _ _
print player ' throws ' choices at random
sleep
In this level you'll learn how to program the game MASH (mansion, apartment, shack, house). In this game you can predict for all the players at once, what their future will look like.
Fill in the blanks by using the new command that you've learned this level.
houses = mansion, apartment, shack, house
loves = nobody, a royal, their neighbour, their true love
pets = dog, cat, elephant
names = Jenna, Ryan, Jim
_
print name ' lives in a ' houses at random
print name ' will marry ' loves at random
print name ' will get a ' pets at random ' as their pet.'
sleep
In this level you can make the turtle draw a figure. The turtle will travel the distances in the list, one by one, making bigger and bigger steps.
Add a 90 degree turn in the loop, so that a spiral is drawn. Add at least 5 numbers to the list, so the spiral grows larger. (extra) can you change the spiral into another shape? Experiment with numbers for the turn!
The spiral is drawn outwards, make it go inwards?
turn 90
distances = 10, 20, 30, 40, 50, 60
for distance in distances
forward distance
Recreate the drawings with the turtle!
Hint Nested Hexagon:
distances = 100, 80, 60, 40, 20
for distance in distances
_
Hint Traffic Lights:
colors = red, yellow, green
for chosen_color in colors
color _
repeat _
Christmas lights
Hint Christmas Lights:
Start by moving to the left side of the screen with an invisible white line. Then hang up the Christmas lights!
color white
turn -90
forward 300
turn 90
colors = red, blue, yellow, purple, green, orange, pink
for chosen_color in colors
_
We can also make a Harry Potter themed fortune teller. Fill in blanks such that 9 lines are printed. Extra Change the theme of the fortune teller into something else, such as your favorite book, film or tv show.
houses = Gryffindor, Slytherin, Hufflepuff, Ravenclaw
subjects = potions, defence against the dark arts, charms, transfiguration
fears = Voldemort, spiders, failing your OWL test
names = Harry, Ron, Hermione
_
_ print name ' is placed in ' houses at random
_ print name ' is great at ' subjects at random
_ print name 's greatest fear is ' fears at random
With for
you can print make the whole baby shark song (including all the other sharks in the family) in only 6 lines!
Can you make the baby shark code even shorter by using a for
command? Finish the example code.
family = baby, mammy, daddy, grandma, grandpa
_ _ _ _
print _
Print the song Five little monkeys jumping on the bed. Look up the text if you don't remember.
Extra Print the song Old MacDonald had a farm, and make sure all animals make a different sound, using an if
.
monkeys = 5, 4, 3, 2, 1
In this level you can use the for
command in your story. In this way you could easily program the children's book 'Brown bear, Brown bear, what do you see'.
Look at the story if you do not know it, and make sure it is printed as in the book.
animals = _ , _ , _
print 'Brown bear, Brown bear'
print 'What do you see?'
In the previous levels you have often made your own rock paper scissors game. Can you finish the code and use the for
command properly to get the game to work?
choices = _
players = _
for _
This calculator game helps you practise your tables of multiplication!
Fill in the blanks. We want this program to ask the player these questions:
How much is 1 times 1?
How much is 1 times 2?
How much is 1 times 3?
How much is 2 times 1?
How much is 2 times 2?
How much is 2 times 3?
How much is 3 times 1?
How much is 3 times 2?
How much is 3 times 3?
_
numbers = 1, 2, 3
for _
for _
answer = ask _
correct = number_1 * number_2
if answer is correct
print 'Great job!'
else
print 'That is wrong. The right answer is ' correct
In this level you'll learn how to easily ask orders for different courses.
Finish the code with an ask
on the blanks such that the customer is asked what they want to eat for each course.
courses = appetizer, main course, dessert
for course in courses
print 'What is your order for ' course '?'
_
_
Of course, you could also order for multiple people! Can you add the correct amount of indentation before each line to make the code work properly? Tip: some lines don't need any indentation at all.
_ courses = appetizer, main course, dessert
_ names = Timon, Ono
_ for name in names
_ for course in courses
_ food = ask name ', what would you like to eat as your ' course '?'
_ print name ' orders ' food ' as their ' course
Debug this code. Good luck!
Warning! This code needs to be debugged!
names = Muad Hasan Samira Noura
activities = fly a kite, go swimming, go hiking, catch tan in the sun
for name is names
print At the beach name loves to activity at random
An error occurred.
An error occurred.
Success
Header
Waiting for a keypress...
Sleeping...
You must be logged in to hand in an assignment.