def stock():
print('Purchase Screws')
length = input('Enter length of the screw (20, 40, 60): ')
while length not in {'20', '40', '60'}:
length = input('Please enter a valid length: ')
material = input('Enter length of the screw (brass, steel): ')
while material not in {'brass', 'steel'}:
material = input('Please enter a valid material: ')
headtype = input('Enter head type of the screw (slot, star, pozidriv): ')
while headtype not in {'slot', 'star', 'pozidriv'}:
headtype = input('Please enter a valid head type: ')
for screw in screwlist:
if screw[0].startswith(material) and screw[1].startswith(headtype) and screw[2].startswith(length):
print(screw)
amount = input('Enter how many you would like to buy (50, 100, 200): ')
while amount not in {'50', '100', '200'}:
amount = input('Please enter a valid amount: ')
if amount == '50':
for screw in screwlist:
current_stock = int(screw[3])
current_stock -= 1
screw[3] = f"{current_stock}"
if amount == '100':
for screw in screwlist:
current_stock = int(screw[4])
current_stock -= 1
screw[4] = f"{current_stock}"
if amount == '200':
for screw in screwlist:
current_stock = int(screw[5])
current_stock -= 1
screw[5] = f"{current_stock}"
with open("screw.txt", "w") as f:
for screw in screwlist:
",".join([screw])
f.write(screwlist)
print(screw)
stock()