in my program the user can input only one of these codes: 86947367 , 78364721 , 35619833 , 84716491 , 46389121 How can I check which one the user has entered with using if statement , an easier method ? part of my code :
if (items[0]) == 86947367 :
with open("read_it.txt") as text_file:
try:
price = int(text_file.readlines()[2])
except ValueError:
print("error")
else:
new_price = int(price * (items2[0]))
print("£",new_price)
elif (items[0]) == 78364721 :
with open("read_it.txt") as text_file:
try:
price1 = int(text_file.readlines()[6])
except ValueError:
print("error")
else:
new_price1 = int(price1 * (items2[0]))
print("£",new_price1)
elif (items[0]) == 35619833 :
with open("read_it.txt") as text_file:
try:
price2 = int(text_file.readlines()[10])
except ValueError:
print("error")
else:
new_price2 = int(price2 * (items2[0]))
print("£",new_price2)
elif (items[0]) == 84716491 :
with open("read_it.txt") as text_file:
try:
price3 = int(text_file.readlines()[14])
except ValueError:
print("error")
else:
new_price3 = int(price3 * (items2[0]))
print("£",new_price3)
NO VERY NEAT IS IT ? THATS WHY I AM ASKING IF AND HOW CAN MY PROGRAM LOOK AT WHAT THE USER HAS ENETERED AND ACCORIDNG TO THAT DO THE FOLLOWING PORCEDURE WITHOUT GOING THROUGH EACH CODE LIKE I HAVE DONE (THIS IS ONLY ONE POART OF MY CODE ).