-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolution,py
52 lines (40 loc) · 1.46 KB
/
solution,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
#!/usr/bin/env python3
from dnd import DNDAPI
class SpellBook:
def __init__(self, spells=dict)-> None:
self.spells: dict = spells
def display_spell(self, spell_data)-> None:
print(f"Name: {spell_data['name']}")
print(f"Level: {spell_data['level']}")
print(f"Index: {spell_data['index']}")
print(f"URL: {spell_data['url']}")
print()
def menu(self)-> None:
print("Welcome to the D&D Spellbook!")
while True:
print("Commands:")
print("1 - List all spells")
print("2 - Search for a spell by name")
print("3 - Exit")
choice = input("Enter your choice: ")
if choice == '1':
print("\nList of Spells:")
for spell in self.spells:
self.display_spell(spell)
elif choice == '2':
spell_name = input("Enter the spell name: ").lower()
matching_spells = [spell for spell in self.spells if spell_name in spell['name'].lower()]
print("\nMatching Spells:")
for spell in matching_spells:
self.display_spell(spell)
elif choice == '3':
print("Goodbye!")
break
else:
print("Invalid choice. Please select a valid option.")
def main():
dnd = DNDAPI()
sp = SpellBook(dnd.spells)
sp.menu()
if __name__ == '__main__':
main()