-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-game-inventory.py
79 lines (72 loc) · 1.74 KB
/
video-game-inventory.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#videogame inventory
import os, time
inventory = []
try:
f = open("inventory.txt", "r")
inventory = eval(f.read())
f.close()
except Exception as err:
#print("ERROR: file not found. Creating new file.")
#print(err)
pass
def add():
time.sleep(1)
os.system("clear")
item = input("Input the item to add: > ").capitalize()
inventory.append(item)
print(f"{item} has been added to your inventory.")
#save to file
f = open("inventory.txt", "w")
f.write(str(inventory))
f.close()
def remove():
time.sleep(1)
os.system("clear")
item = input("Input the item to remove: > ").capitalize()
if item in inventory:
inventory.remove(item)
print(f"{item} has been removed from your inventory.")
else:
print(f"No {item} found in the inventory.")
#save to file
f = open("inventory.txt", "w")
f.write(str(inventory))
f.close()
def view():
time.sleep(1)
os.system("clear")
item = input("Input the item to view: > ").capitalize()
if item in inventory:
#counter = 0
#for i in inventory:
#if i == item:
#counter += 1
counter = inventory.count(item)
print(f"You have {counter} {item}")
else:
print(f"No {item} found in the inventory.")
#save to file
f = open("inventory.txt", "w")
f.write(str(inventory))
f.close()
while True:
time.sleep(1)
os.system("clear")
print("🌟RPG Inventory🌟")
menu = input("1: Add\n2: Remove\n3: View\n4: Exit\n> ")
if menu == "1":
add()
continue
elif menu =="2":
remove()
continue
elif menu =="3":
view()
continue
elif menu == "4":
break
else:
print("Invalid selection. Please try again.")
continue
print()
print("Bye!")