-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_list.py
35 lines (27 loc) · 907 Bytes
/
random_list.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
import random
random_list = []
# Function to display help options
def show_help():
print("Welcome to the random item selector")
print("Enter items and then a random item will be selected")
print("Enter DONE to finish")
print("Enter HELP to display commands")
def get_random_item():
upper_bound = len(random_list)
random_index = random.randint(0, upper_bound)
random_sel_item = random_list[random_index]
print("The random selection is: {}".format(random_sel_item))
# Main function
def main():
show_help()
while True:
input_item = input("Enter item > ")
if input_item.upper() == 'DONE':
print(get_random_item())
break
elif input_item.upper() == 'HELP':
show_help()
else:
random_list.append(input_item)
print("Added {} to the list.".format(input_item))
main()