forked from parthbheda/pythoniffie
-
Notifications
You must be signed in to change notification settings - Fork 3
/
shoppinglist.py
64 lines (59 loc) · 1.91 KB
/
shoppinglist.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
import cPickle as p
einkaufsdatei = 'einkaufsliste.data' # Die Daei in die die Einkauflsite immer gespeichert werden soll
try:
f = file(einkaufsdatei)
gl = p.load(f)
except:
einkaufsliste = [] # Die Liste
f = file(einkaufsdatei, 'w')
p.dump(einkaufsliste, f)
f.close()
del einkaufsliste
f = file(einkaufsdatei)
gl = p.load(f)
def menue(): # Das Menue
print '- - - - - - - - - - - - - - - - - - - - - - -'
print 'Welcome!'
print 'Please press...'
print '1 to view your shopping list'
print '2 to add a product to shopping list'
print '3 to delete a product that you already bought'
print '4 to save your shopping list'
print '5 to close the program'
print '- - - - - - - - - - - - - - - - - - - - - - - '
while True:
menue()
option = raw_input('You choose: ')
if option == '1':
if len(gl) > 0:
print 'Your shopping list contains following objects:'
for item in gl:
print item
else:
print 'DYour list is empty!'
elif option == '2':
neues_produkt = raw_input('Please enter the product you want to buy: ')
gl.append(neues_produkt)
print 'PProduct added!'
elif option == '3':
loesch_produkt = raw_input('Please enter the product you want to delete ')
while loesch_produkt in gl:
produkt_nummer = gl.index(loesch_produkt)
del gl[produkt_nummer]
print 'The product has been removed'
break
else:
print 'The product is in your shopping list'
elif option == '4':
f = file(einkaufsdatei, 'w')
p.dump(gl, f)
f.close()
del gl
f = file(einkaufsdatei)
gl = p.load(f)
print 'Your shopping list has been saved!'
elif option == '5':
print 'See you soon!'
break
else:
print 'Error! Choose one of the 5 options'