This page contains a number of questions and exercises to give you a chance to practise what you have learned this session.
You should create a new .py
Python file for each exercise.
Create a list containing 5 different animal types, for example:
Print out the list to the screen.
Start by copying the code that you used to create the list of animals in the last exercise. Write a loop which will print out each of the animals, prefixed with Species:
. For example the output could look like:
Species: cat
Species: dog
Species: elephant
Species: minnow
Species: beaver
Create a list containing 10 different numbers, ranging from 0 to 100. For example: $65, 54, 17, 78, 66, 24, 32, 80, 79, 95$.
Write a loop which will print out only those numbers which are larger than 50.
Create a loop which iterates over the numbers from 1 to 20 (inclusive). Inside the loop:
Make a dictionary from the following table of data. The keys of the dictionary should be the names of the paintings and the values should be name of the artist.
Painting | Artist |
---|---|
Sunflowers | van Gogh |
The Starry Night | van Gogh |
The Night Watch | Rembrandt |
The Two Fridas | Kahlo |
Balloon Girl | Banksy |
Devolved Parliament | Banksy |
Going to Work | Lowry |
Write some code which will print out the work of art and the name of the artist if:
Make a dictionary of the same information as the last question, but the other way around this time. The key in the dictionary should be the name of the artist, and the value should be a list of names of their paintings.
Write some code which will check every painting in the data set. Print out the work of art and the name of the artist if:
Create a list with some words in it, making sure some words are repeated.
The task is to fill up a dictionary so that it contains the count of the number of times each word appears in the list.
So, for example if your word list looks like:
word_list = ["to", "be", "or", "not", "to", "be"]
then the output dictionary would look like:
{"to": 2, "be": 2, "or": 1. "not": 1}