-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheads_up.py
41 lines (33 loc) · 1.11 KB
/
heads_up.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
import random
# Name of the file to read in!
FILE_NAME = 'cswords.txt'
def get_words_from_file():
"""
This function has been implemented for you. It opens a file,
and stores all of the lines into a list of strings.
It returns a list of all lines in the file.
"""
f = open(FILE_NAME)
lines = []
for line in f:
# removes whitespace characters (\n) from the start and end of the line
line = line.strip()
# if the line was only whitespace characters, skip it
if line != "":
lines.append(line)
return lines
def main():
# m1: print all items on the list
lines_list = get_words_from_file()
# Find the data type of a variable
# print(type(lines_list))
# m2: show a randomly chosen word
# print(random.choice(lines_list))
# m3: continue when the user hits enter with another random word
while True:
random_word = random.choice(lines_list)
print(random_word)
# take enter as a blank input from the user
input("Press enter to continue")
if __name__ == '__main__':
main()