-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive_jungle.py
More file actions
90 lines (75 loc) · 3.37 KB
/
interactive_jungle.py
File metadata and controls
90 lines (75 loc) · 3.37 KB
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
81
82
83
84
85
86
87
88
89
90
import random
class InteractivePrompt:
@staticmethod
def get_choice(prompt, options):
while True:
print(prompt)
for i, option in enumerate(options, start=1):
print(f"{i}. {option}")
try:
choice = int(input("Enter your choice: "))
if 1 <= choice <= len(options):
return choice
else:
print("Invalid choice. Please try again.")
except ValueError:
print("Invalid input. Please enter a number.")
def run(self):
print("Welcome to the Interactive Prompt!")
while True:
category_choice = self.get_choice(
"Choose a category:",
["Car", "Animal", "Food", "Exit"]
)
if category_choice == 1: # Car
car_makers = ["Toyota", "Ford", "Honda"]
car_maker_choice = self.get_choice(
"Choose a car maker:",
car_makers
)
selected_maker = car_makers[car_maker_choice - 1]
car_models = ["Camry", "Mustang", "Civic"]
selected_model = random.choice(car_models)
print(f"Vroom, vroom! You selected a {selected_maker} {selected_model}")
elif category_choice == 2: # Animal
animal_types = ["Mammals", "Birds", "Fish"]
animal_type_choice = self.get_choice(
"Choose a type of animal:",
animal_types
)
selected_type = animal_types[animal_type_choice - 1]
if selected_type == "Mammals":
mammals = ["Dog", "Cat", "Elephant"]
selected_animal = random.choice(mammals)
elif selected_type == "Birds":
birds = ["Sparrow", "Eagle", "Penguin"]
selected_animal = random.choice(birds)
else:
fish = ["Salmon", "Tuna", "Shark"]
selected_animal = random.choice(fish)
print(f"Good fella! This is a {selected_animal}")
elif category_choice == 3: # Food
food_types = ["Dessert", "Fruit", "Beverage"]
food_type_choice = self.get_choice(
"Choose a type of food:",
food_types
)
selected_type = food_types[food_type_choice - 1]
if selected_type == "Dessert":
desserts = ["Cake", "Ice Cream", "Cookies"]
selected_food = random.choice(desserts)
elif selected_type == "Fruit":
fruits = ["Apple", "Banana", "Orange"]
selected_food = random.choice(fruits)
else:
beverages = ["Coffee", "Tea", "Soda"]
selected_food = random.choice(beverages)
print(f"Yummy, this is a {selected_food}")
elif category_choice == 4: # Exit
print("Thank you for using the interacive module. Goodbye!")
break
else:
print("Fatal error! Please try again.")
if __name__ == "__main__":
prompt = InteractivePrompt()
prompt.run()