I am having a problem where the user enters various codes , into 1 variable and then i want to split these input to make it into a list.However , I have realized that my variable only takes in the last input meaning the list comes out with only one code and not several. How do I make a variable store multiple inputs ?
while True:
itemsneeded = input("How many items do you need?")
if itemsneeded.isnumeric() and int(itemsneeded) <= 5:
break
GTIN = ''
count = 0
while count < int(itemsneeded):
GTIN = (input('Please enter all GTIN-8 for all items'))
if GTIN.isnumeric() and len(GTIN) == 8:
Num0 = int(GTIN[0]) * 3
Num1 = int(GTIN[1])
Num2 = int(GTIN[2]) * 3
Num3 = int(GTIN[3])
Num4 = int(GTIN[4]) * 3
Num5 = int(GTIN[5])
Num6 = int(GTIN[6]) * 3
Num7 = int(GTIN[7])
total2 = (Num0 + Num1 + Num2 + Num3 + Num4 + Num5 + Num6 + Num7)
if total2 % 10 == 0:
print(GTIN)
if GTIN in open('read_it.txt').read():
print('entered GTIN is valid')
else:
print('The code entered is invalid')
print('Please renter this code')
count += 1
else:
print("The entered GTIN-8 codes are incorrect")
print(GTIN)
lst = GTIN.split()
print(lst)
And I can not use this (Two values from one input in python?) becuase I do not know how many items the user wants , the users input can vary from 1 item to 5.