Yi Sang’s Poem No. 1
We noticed that many of you find it hard to work with dictionaries and add values. Hence the following assignment. I’ve also received feedback that many of you enjoyed the difficult excersise in recreating Yi Sang’s poem. To not deny those that have not worked on it the pleasure of his work, we will again follow his poem No1 (translated in english).
Copy the following code block into your own notebook and good luck!
Focus on doing this assingment in steps if you find it hard. Start with the for loop, and expand from their. Use the hint section (below) to get help.
poem = """
13 children speed toward the way.
(For the road a blocked alley is apt.)
The 1st child says it is scary.
The 2nd child says it is scary.
The 3rd child says it is scary.
The 4th child says it is scary.
The 5th child says it is scary.
The 6th child says it is scary.
The 7th child says it is scary.
The 8th child says it is scary.
The 9th child says it is scary.
The 10th child says it is scary.
The 11th child says it is scary.
The 12th child says it is scary.
The 13th child says it is scary.
Among 13 children there are scary children and
scared children and they are all they are. (It is
better that there is no other excuse.)
Of those it is fine to say that 1 child is scary.
Of those it is fine to say that 2 children are scary.
Of those it is fine to say that 2 children are scared.
Of those it is fine to say that 1 child is scared.
(For the road an opened one is apt.)
It does not matter if 13 children do not speed toward the way.
"""
Good luck. The solutions will be uploaded the next day along with the new practice assignment.
Click here to see Hint 1
first check if you can print each words present in the poem using a for loop.
Hint 1 Solution
first check if you can print each words present in the poem using a for loop.
# using .split() on any text will turn it into a list of words, sepearting by whitespace.
poem_dict = {}
for word in poem.split():
print(word)
Click here to see Hint 2
You will need an if-else statement in your for loop
do a sanity check of your if else statement. Check if what is happening is indeed happening.
Hint 2 Solution
You will need an if-else statement in your for loop
do a sanity check of your if else statement. Check if what is happening is indeed happening.
I do this through the following:
- adding 1 word to the dictionary
- check if 'excuse' in poem_dict indeed returns True. (it should..)
- check if 'test' in poem_dict return False. (it should..)
# next we write an if statement
poem_dict = {}
poem_dict['excuse'] = 1
# will be in my if statement - should return True.
print('excuse' in poem_dict)
# should return False
print('test' in poem_dict)