-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvendingscript.py
76 lines (62 loc) · 2.11 KB
/
vendingscript.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
#python script for a vending machine
#it can only handle one item at the time.
#import time library to pause and to measure the time between start and end
import time
#array with products - extend as you please
snacks = ['1. Snickers', '2. Mars', '3. Doritos']
#array with prices
prices = ['2.50', '2.00', '3.00']
#array with amount in store
storage = [10, 5, 1]
def calc():
for i in (storage):
if i < 1:
print(storage(i))
print(storage.index)
#for i in range(len(storage)):
#if i < 1:
#storage.pop(i)
#snacks.pop(csnack)
#try and catch to avoid an unplanned exit
while True:
try:
#start of the programm
start = int(time.time())
print("Please select one of the Snacks listed below\n")
print("\n".join(snacks))
choice = int(input())
#calculate index position
csnack = choice - 1
chose = snacks[csnack]
#calculate new item count
amount = storage[csnack] - 1
#set new item count in array
storage[csnack] = amount
#print array with new amount of items
print(storage)
if storage[csnack] < 1:
print("Less than one")
else:
print("All good")
# if amount < 1 return error and pop item out of list
#for i in range(len(storage)):
# if i < 1:
# print(i)
# storage.pop(i)
#call function calc
#calc()
#print the array with the amount of items left
print(amount)
print(chose + "\n")
#end of the programm
end = int(time.time())
#print(end - start)
print("Please wait until the machine is ready again!")
#wait for 10 seconds until machine is ready again
#time.sleep(10)
#if input is not a int value - this error will be printed
except ValueError:
print("Please enter a valid number!\n")
#if input int value is higher than a index number in array - this error will be printed
except IndexError:
print("This number is not included in the list\n")