Due: Tuesday the 13th of November 2018 20:00 p.m.
Please name your ipython notebook with the following naming convention: ASSIGNMENT_2_FIRSTNAME_LASTNAME.ipynb
Please submit your assignment using this google form
If you have questions about this topic, please post them in the Canvas forum.
The song's simple lyrics are as follows:
99 bottles of beer on the wall,
99 bottles of beer.
Take one down, pass it around,
98 bottles of beer on the wall.
The same verse is repeated, each time with one fewer bottle. The song is completed when the singer or singers reach zero. After the last bottle is taken down and passed around, there is a special verse:
No more bottles of beer on the wall,
no more bottles of beer.
Go to the store and buy some more,
99 bottles of beer on the wall.
Notes:
Hint:
number = number - 1
You can use the following code snippet as a start:
In [ ]:
for number in reversed(range(1, 5)): # change 5 to 99 when you're done with debugging
print(number, 'bottles of beer on the wall,')
In this exercise, we will focus on the following list methods:
a.) append
b.) count
c.) index
d.) insert
e.) pop
For each of the aforementioned list methods:
In this exercise, we will focus on the following set methods:
For each of the aforementioned set methods:
These stories were copied from here.
In [ ]:
a_story = """In a far away kingdom, there was a river. This river was home to many golden swans. The swans spent most of their time on the banks of the river. Every six months, the swans would leave a golden feather as a fee for using the lake. The soldiers of the kingdom would collect the feathers and deposit them in the royal treasury.
One day, a homeless bird saw the river. "The water in this river seems so cool and soothing. I will make my home here," thought the bird.
As soon as the bird settled down near the river, the golden swans noticed her. They came shouting. "This river belongs to us. We pay a golden feather to the King to use this river. You can not live here."
"I am homeless, brothers. I too will pay the rent. Please give me shelter," the bird pleaded. "How will you pay the rent? You do not have golden feathers," said the swans laughing. They further added, "Stop dreaming and leave once." The humble bird pleaded many times. But the arrogant swans drove the bird away.
"I will teach them a lesson!" decided the humiliated bird.
She went to the King and said, "O King! The swans in your river are impolite and unkind. I begged for shelter but they said that they had purchased the river with golden feathers."
The King was angry with the arrogant swans for having insulted the homeless bird. He ordered his soldiers to bring the arrogant swans to his court. In no time, all the golden swans were brought to the King’s court.
"Do you think the royal treasury depends upon your golden feathers? You can not decide who lives by the river. Leave the river at once or you all will be beheaded!" shouted the King.
The swans shivered with fear on hearing the King. They flew away never to return. The bird built her home near the river and lived there happily forever. The bird gave shelter to all other birds in the river. """
print(a_story)
In [ ]:
another_story = """Long time ago, there lived a King. He was lazy and liked all the comforts of life. He never carried out his duties as a King. “Our King does not take care of our needs. He also ignores the affairs of his kingdom." The people complained.
One day, the King went into the forest to hunt. After having wandered for quite sometime, he became thirsty. To his relief, he spotted a lake. As he was drinking water, he suddenly saw a golden swan come out of the lake and perch on a stone. “Oh! A golden swan. I must capture it," thought the King.
But as soon as he held his bow up, the swan disappeared. And the King heard a voice, “I am the Golden Swan. If you want to capture me, you must come to heaven."
Surprised, the King said, “Please show me the way to heaven." “Do good deeds, serve your people and the messenger from heaven would come to fetch you to heaven," replied the voice.
The selfish King, eager to capture the Swan, tried doing some good deeds in his Kingdom. “Now, I suppose a messenger will come to take me to heaven," he thought. But, no messenger came.
The King then disguised himself and went out into the street. There he tried helping an old man. But the old man became angry and said, “You need not try to help. I am in this miserable state because of out selfish King. He has done nothing for his people."
Suddenly, the King heard the golden swan’s voice, “Do good deeds and you will come to heaven." It dawned on the King that by doing selfish acts, he will not go to heaven.
He realized that his people needed him and carrying out his duties was the only way to heaven. After that day he became a responsible King.
"""
Before analyzing the two texts, we are first going to preprocess them. Please use a particular string method multiple times to replace the following characters by empty strings in both a_story and another_story:
After preprocessing both texts, please call the cleaned stories cleaned_story and cleaned_another_story
In [ ]:
vocab_a_story = set()
for word in cleaned_story:
# insert your code here
do the same for the other text
In [ ]:
# you code
In [ ]:
# your code
Below you find a list called words, which is a list of strings.
a.) Please create a dictionary in which the key is the word and the value is the frequency of the word. However, do not include words that:
You are not allowed to use the collections module to do this.
In [ ]:
words = ['there',
'was',
'a',
'village',
'near',
'a',
'jungle',
'the',
'village',
'cows',
'used',
'to',
'go',
'up',
'to',
'the',
'jungle',
'in',
'search',
'of',
'food.',
'in',
'the',
'forest',
'there',
'lived',
'a',
'wicked',
'lion',
'he',
'used',
'to',
'kill',
'a',
'cow',
'now',
'and',
'then',
'and',
'eat',
'her',
'this',
'was',
'happening',
'for',
'quite',
'sometime',
'the',
'cows',
'were',
'frightened',
'one',
'day',
'all',
'the',
'cows',
'held',
'a',
'meeting',
'an',
'old',
'cow',
'said',
'listen',
'everybody',
'the',
'lion',
'eats',
'one',
'of',
'us',
'only',
'because',
'we',
'go',
'into',
'the',
'jungle',
'separately',
'from',
'now',
'on',
'we',
'will',
'all',
'be',
'together',
'from',
'then',
'on',
'all',
'the',
'cows',
'went',
'into',
'the',
'jungle',
'in',
'a',
'herd',
'when',
'they',
'heard',
'or',
'saw',
'the',
'lion',
'all',
'of',
'them',
'unitedly',
'moo',
'and',
'chased',
'him',
'away',
'moral',
'divided',
'we',
'fall',
'united',
'we',
'stand']
b.) Analyze your dicitionary by printing:
In [ ]:
In addition, print the frequencies of the following words using your dictionary (if the word does not occur in the dictionary, print 'WORD does not occur')
In [ ]:
for word in ['up', 'near' , 'lion']:
# print frequency
a. What is the difference between positional arguments and keyword arguments?
In [ ]:
b. What is/are the type/types of containers that you define using curly brackets?
In [ ]:
c. When comparing the containers lists and sets, there are three properties that are unique for lists. Please name and explain them.
In [ ]:
d. Explain the difference between continue and break? You can use an example for this.
In [ ]: