-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
80 lines (61 loc) · 2.09 KB
/
errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This method breaks up text into words for us
def break_words(text):
words = text.split()
return words
# Counts the number of words
def count_words(words):
print(len(words))
# Sorts the words (alphabetically)
def sorted_words(words):
words.sort()
return words
# Takes in a full sentence and returns the sorted words
def sort_sentence(sentence):
words = break_words(sentence)
return sorted_words(words)
# Prints the first word after popping it off
def print_first_word(words):
word = words.pop(0)
print(word)
# Prints the last word after popping it off
def print_last_word(words):
word = words.pop(-1)
print(word)
# Prints the first and last words of the sentence
def print_first_and_last_word(sentence):
words = break_words(sentence)
print_first_word(words)
print_last_word(words)
demitri_martin_joke = """I used to play sports.
Then I realized you can buy trophies. Now I am good at everything."""
print("----------")
print(demitri_martin_joke)
print("----------")
bottles_of_beer = 100 + 10 - 15 + 4
print("This should be ninety-nine:", bottles_of_beer)
def sing(bottles):
for number in reversed(range(bottles + 1)):
if number > 0:
print_verse(number)
else:
print_last_verse()
def print_verse(bottles):
print(bottles, "bottles of beer on the wall,", end=' ')
print(bottles, "bottles of beer.")
print("Take one down and pass it around,", end=' ')
print(bottles - 1, "bottles of beer on the wall.\n")
def print_last_verse():
print("No more bottles of beer on the wall,", end=' ')
print("no more bottles of beer.")
print("Go to the store and buy some more,", end=' ')
print("99 bottles of beer on the wall.\n")
sing(bottles_of_beer)
sentence = "\"I think it's interesting that 'cologne' rhymes with 'alone'\""
words = break_words(sentence)
sorted_words = sort_sentence(sentence)
print("{} has {} words".format(sentence, len(words)))
print("The words are:", words)
print("The sorted words are:", sorted_words)
print_first_word(words)
print_last_word(words)
print_first_and_last_word(sentence)