-
Notifications
You must be signed in to change notification settings - Fork 2
/
haiku.py
executable file
·65 lines (55 loc) · 1.88 KB
/
haiku.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
import random
import wn
import syl
print("The title of your haiku is:", "the", wn.randomword('a','eng'), wn.randomword('n', 'eng'))
while True:
line1 = input("Type your haiku here:\n")
counter1 = syl.noofsyllables(line1)
if counter1 != 5:
print("There should be exactly 5 syllables in line 1. I counted " + str(counter1) )
if counter1 == 5:
break
#while True:
#line2 = input()
#counter2 = syl.noofsyllables(line2)
#if counter2 != 7:
#print("There should be exactly 7 syllables in line 2. I counted " + str(counter2))
#if counter2 == 7:
#break
rannum = random.randint(1,5)
ranword = wn.randomword('a','eng')
while True:
if rannum in [1,2,3,4,5]:
print ("You must use", '"', ranword, '"', "in this second line.")
line2 = input()
wordlist = line2.split()
#swordlist= stripped wordlist
swordlist = []
for word in wordlist:
word = word.lower().strip(".:;?!")
swordlist.append(word)
print (swordlist)
if ranword in swordlist:
counter2 = syl.noofsyllables(line2)
if counter2 != 7:
print("There should be exactly 7 syllables in line 2. I counted " + str(counter2))
if counter2 == 7:
break
else:
print ("You must try again.")
else:
line2 = input()
counter2 = syl.noofsyllables(line2)
if counter2 != 7:
print("There should be exactly 7 syllables in line 2. I counted " + str(counter2))
if counter2 == 7:
break
while True:
line3 = input()
counter3 = syl.noofsyllables(line3)
if counter3 != 5:
print("There should be exactly 5 syllables in line 3. I counter " + str(counter3))
if counter3 == 5:
break
print("Good job! This is your haiku: \n")
print (line1 + "\n" + line2 + "\n" + line3)