Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- valid=False ## stores variables
- bartotal1=0 ##" "
- beantotal1=0 ##" "
- tunatotal1=0 ##" "
- skittletotal1=0 ##" "
- beanstock=15 ##" "
- tunastock=11 ##" "
- skittlestock=17 ##" "
- barstock=24 ##" "
- finalbill=0 ##" "
- beans1=0 ##" "
- tuna1=0 ##" "
- skittle1=0 ##" "
- bar1=0 ##" "
- channel=open('List1.txt','w') ## writes a text file with information below
- beans = channel.write(('82571465 Can of Beans £0.86 15')+'n') ##adds a new line into text file
- tuna = channel.write(('28528243 Tin of Tuna £1.12 11')+'n') ##adds a new line into text file
- skittle = channel.write(('71616799 Skittles £2.14 17')+'n') ##adds a new line into text file
- bar = channel.write(('48156322 Bar of Chocolate £0.99 24')+'n') ##adds a new line into text file
- channel.close() ##closes the writing text file
- channel=open('List.txt','r') ##reads a set up text file in neat
- for line in channel: ##
- print(line) ##prints out the text file line by line
- channel.close() ##
- while valid==False: ##starts a loop including all below
- valid=True ##sets valid true to start loop
- print(" ") ##
- print("Type the Gtin of what you would like to buy below...") ##asks the user what they want to buy from the list
- print(" ") ##
- want = input("What item would you like to purchase: ") ##lets the user input what they want to buy
- print(" ") ##
- if (want == "82571465") or (want == "28528243") or (want == "71616799") or (want == "48156322"): ##if input doesnt equal one of these on the list it automatically restarts the loop
- if want=="82571465": ##looks if the input was equal to this
- print(beanstock," cans of beans in stock...") ##print amount of stock stored
- beans1 = int(input("How many Can of Beans would you like to buy: ")) ##asks user to input how many they want to buy
- if 1 <= beans1 <= beanstock: ##checks if input is in range of stock
- print ("Added") ##
- print(" ") ##
- beantotal1 = (0.86*beans1)##calculates how much they have to pay for the amount they want by the price
- print(round(beantotal1,2)) ##prints how much it costs to 2 decimal places
- round(beantotal1,2) ##rounds amount to store for final bill
- beanstock = (beanstock-beans1) ## takes the amount user wants from the total stock
- else: ##if it the input isnt in range of stock it prints this out
- print("We currently don't have that many in stock, please try again...") ##
- valid=False ##restarts the loop if not in range of stock
- if want=="28528243": ##looks if the input was equal to this
- print(tunastock," tins of tuna in stock...") ##prints amount of stock stored
- tuna1 = int(input("How many Tins of tuna would you like to buy: ")) ##asks user to input how many they want to buy
- if 1 <= tuna1 <= tunastock: ## checks if input is in range of stock
- print(tuna1," Added to shopping list") ##
- print(" ") ##
- tunatotal1= (1.12*tuna1) ##calculates how much they have to pay for the amount they want by the price
- print(round(tunatotal1,2)) ##prints how much it costs to 2 decimal places
- round(tuna1,2) ##rounds amount to store for the final bill
- tunastock = (tunastock-tuna1) ## takes the amount user wants from the total stock
- else: ##if input isnt in range of stock this is printed out
- print("We currently don't have that many in stock, please try again...") ##
- valid=False ##restarts the loop if not in range of stock
- if want=="71616799": ##looks if the input was equal to this
- print(skittlestock," bags of skittles in stock...") ##prints amount of stock stored
- skittle1 = int(input("How many Packs of Skittles would you like to buy: ")) ##asks user to input how many they want
- if 1 <= skittle1 <= skittlestock: ## checks if the input is in range of stock
- print(skittle1," Added to shopping list") ##
- print(" ") ##
- skittletotal1 = (2.14*skittle1) ##calculates how much the user has to pay for the amount they want by the price
- print(round(skittletotal1,2)) ## prints how much it costs to 2 decimal places
- round(skittle1,2) ##rounds amount to store the final bill
- skittlestock = (skittlestock-skittle1) ##takes the amount the user wants from the total stock
- else: ##if the user input is not in range of stock this is printed out
- print("We currently don't have that many in stock, please try again...") ##
- valid=False ##restarts loop if not in range of stock
- if want=="48156322": ##looks if the input was equal to this
- print(barstock," bars of chocolate in stock...") ##prints amount of stock stored
- bar1 = int(input("How many Bars of Chocolate would you like to buy: ")) ##asks user to input how many they want
- if 1 <= bar1 <= barstock: ## checks if the input is in range of stock
- print(bar1," Added to shopping list") ##
- print(" ") ##
- bartotal1 = (0.99*bar1) ##calculates how much the user has to pay for the amount they want by the price
- print(round(bartotal1,2)) ## prints how much it costs to 2 decimal places
- round(bar1,2) ##rounds amount to store the final bill
- barstock = (barstock-bar1) ##takes the amount the user wants from the total stock
- else: ##if the user input is not in range of stock this is printed out
- print("We currently don't have that many in stock, please try again...") ##
- valid=False ##restarts loop if not in range of stock
- yesno = input("Would you like anything else? (yes/no): ") ##asks the user if they want to buy anything else after each of the products listed
- if (yesno == "no") or (yesno=="No"): ##checks if the user does want to buy something else, if no...
- finalbill = float(bartotal1) + float(skittletotal1) + float(beantotal1) + float(tunatotal1) ##the final bill is stored
- print(beans1," Cans of Beans") ##prints out how many cans of beans they wanted to buy
- print(tuna1," Tins of Tuna") ##prints out how many tins of tuna they wanted to buy
- print(skittle1," Bags of Skittles") ##prints out how many bags of skittles they wanted to buy
- print(bar1," Bars of Chocolate") ##prins out how many bars of chocolate they wanted to buy
- print("** ",beans1 + tuna1 + skittle1 + bar1," items bought in total **") ##prints the total amount of items they purchased
- print("Your final bill is: ") ##
- print(round(finalbill,2))##prints out the total amount of money they have to pay for the items they purchased to 2 decimal places
- channel=open('List1.txt','w')
- valid=True ##ends program
- else: ##if they want to buy something else it sends them back to the stored items for them to purchase more and stores what they have already added to their shopping list
- valid=False ##goes back to the stock
- else: ##
- quit()## if no gtin from the stocked items is typed in it exits the program for them to open up and restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement