Академический Документы
Профессиональный Документы
Культура Документы
Name:
What does the line printallRides do?
Task 2 - Lists
It is often more useful to store information as a list instead of a string.
This is similar to an array in other programming languages.
Write a new program in a new window which stores each type of ride in a
list
rollercoasters=['python','cobra','viper','copperhead']
familyRides=['twister','bigwheel','ghosttrain']
waterRides=['logflume','rattlesnakerapids','lazyriver']
childRides=['babysnake','snakejungle','spinningteapots']
allRides=rollercoasters+waterRides+familyRides+childRides
printallRides
What is printed on screen this time when you ran the code?
What happens if you type print allRides[0] into the python shell?
What happens when you type print allRides[4:6] into the python
shell?
What would you type into python to print out just a list of the family
rides?
Name:
Check it works
Task 3 - Dictionaries/Maps
Another data type in Python is a Dictionary (sometimes called a Map).
This is similar to a list but has a key which can be used to find the
information quickly.
Find out which ride six people in the class prefer and enter them into the
table below.
Name
In Python {} are used to create a Dictionary. Each element has a key and
value.
favouriteRide={Matthew:Water,Jenny:Family,Cara:Rollercoaster,
Jimmy:Rollercoaster}
Open a new window and create a Dictionary to store the favourite rides
for the pupils that you entered into the table above.
Write a command to print out your dictionary
What do you notice about what is printed on screen?
Write a command to print out just one persons favourite ride (Hint print
favouriteRide[name])
Name: