Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. valid=False ## stores variables
  2. bartotal1=0 ##" "
  3. beantotal1=0 ##" "
  4. tunatotal1=0 ##" "
  5. skittletotal1=0 ##" "
  6. beanstock=15 ##" "
  7. tunastock=11 ##" "
  8. skittlestock=17 ##" "
  9. barstock=24 ##" "
  10. finalbill=0 ##" "
  11. beans1=0 ##" "
  12. tuna1=0 ##" "
  13. skittle1=0 ##" "
  14. bar1=0 ##" "
  15.  
  16. channel=open('List1.txt','w') ## writes a text file with information below
  17. beans = channel.write(('82571465 Can of Beans £0.86 15')+'n') ##adds a new line into text file
  18. tuna = channel.write(('28528243 Tin of Tuna £1.12 11')+'n') ##adds a new line into text file
  19. skittle = channel.write(('71616799 Skittles £2.14 17')+'n') ##adds a new line into text file
  20. bar = channel.write(('48156322 Bar of Chocolate £0.99 24')+'n') ##adds a new line into text file
  21. channel.close() ##closes the writing text file
  22.  
  23. channel=open('List.txt','r') ##reads a set up text file in neat
  24. for line in channel: ##
  25. print(line) ##prints out the text file line by line
  26. channel.close() ##
  27.  
  28. while valid==False: ##starts a loop including all below
  29. valid=True ##sets valid true to start loop
  30.  
  31. print(" ") ##
  32. print("Type the Gtin of what you would like to buy below...") ##asks the user what they want to buy from the list
  33. print(" ") ##
  34. want = input("What item would you like to purchase: ") ##lets the user input what they want to buy
  35. print(" ") ##
  36.  
  37. 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
  38.  
  39. if want=="82571465": ##looks if the input was equal to this
  40. print(beanstock," cans of beans in stock...") ##print amount of stock stored
  41. beans1 = int(input("How many Can of Beans would you like to buy: ")) ##asks user to input how many they want to buy
  42. if 1 <= beans1 <= beanstock: ##checks if input is in range of stock
  43. print ("Added") ##
  44. print(" ") ##
  45. beantotal1 = (0.86*beans1)##calculates how much they have to pay for the amount they want by the price
  46. print(round(beantotal1,2)) ##prints how much it costs to 2 decimal places
  47. round(beantotal1,2) ##rounds amount to store for final bill
  48. beanstock = (beanstock-beans1) ## takes the amount user wants from the total stock
  49. else: ##if it the input isnt in range of stock it prints this out
  50. print("We currently don't have that many in stock, please try again...") ##
  51. valid=False ##restarts the loop if not in range of stock
  52.  
  53. if want=="28528243": ##looks if the input was equal to this
  54. print(tunastock," tins of tuna in stock...") ##prints amount of stock stored
  55. tuna1 = int(input("How many Tins of tuna would you like to buy: ")) ##asks user to input how many they want to buy
  56. if 1 <= tuna1 <= tunastock: ## checks if input is in range of stock
  57. print(tuna1," Added to shopping list") ##
  58. print(" ") ##
  59. tunatotal1= (1.12*tuna1) ##calculates how much they have to pay for the amount they want by the price
  60. print(round(tunatotal1,2)) ##prints how much it costs to 2 decimal places
  61. round(tuna1,2) ##rounds amount to store for the final bill
  62. tunastock = (tunastock-tuna1) ## takes the amount user wants from the total stock
  63. else: ##if input isnt in range of stock this is printed out
  64. print("We currently don't have that many in stock, please try again...") ##
  65. valid=False ##restarts the loop if not in range of stock
  66.  
  67. if want=="71616799": ##looks if the input was equal to this
  68. print(skittlestock," bags of skittles in stock...") ##prints amount of stock stored
  69. skittle1 = int(input("How many Packs of Skittles would you like to buy: ")) ##asks user to input how many they want
  70. if 1 <= skittle1 <= skittlestock: ## checks if the input is in range of stock
  71. print(skittle1," Added to shopping list") ##
  72. print(" ") ##
  73. skittletotal1 = (2.14*skittle1) ##calculates how much the user has to pay for the amount they want by the price
  74. print(round(skittletotal1,2)) ## prints how much it costs to 2 decimal places
  75. round(skittle1,2) ##rounds amount to store the final bill
  76. skittlestock = (skittlestock-skittle1) ##takes the amount the user wants from the total stock
  77. else: ##if the user input is not in range of stock this is printed out
  78. print("We currently don't have that many in stock, please try again...") ##
  79. valid=False ##restarts loop if not in range of stock
  80.  
  81. if want=="48156322": ##looks if the input was equal to this
  82. print(barstock," bars of chocolate in stock...") ##prints amount of stock stored
  83. bar1 = int(input("How many Bars of Chocolate would you like to buy: ")) ##asks user to input how many they want
  84. if 1 <= bar1 <= barstock: ## checks if the input is in range of stock
  85. print(bar1," Added to shopping list") ##
  86. print(" ") ##
  87. bartotal1 = (0.99*bar1) ##calculates how much the user has to pay for the amount they want by the price
  88. print(round(bartotal1,2)) ## prints how much it costs to 2 decimal places
  89. round(bar1,2) ##rounds amount to store the final bill
  90. barstock = (barstock-bar1) ##takes the amount the user wants from the total stock
  91. else: ##if the user input is not in range of stock this is printed out
  92. print("We currently don't have that many in stock, please try again...") ##
  93. valid=False ##restarts loop if not in range of stock
  94.  
  95. 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
  96.  
  97. if (yesno == "no") or (yesno=="No"): ##checks if the user does want to buy something else, if no...
  98. finalbill = float(bartotal1) + float(skittletotal1) + float(beantotal1) + float(tunatotal1) ##the final bill is stored
  99. print(beans1," Cans of Beans") ##prints out how many cans of beans they wanted to buy
  100. print(tuna1," Tins of Tuna") ##prints out how many tins of tuna they wanted to buy
  101. print(skittle1," Bags of Skittles") ##prints out how many bags of skittles they wanted to buy
  102. print(bar1," Bars of Chocolate") ##prins out how many bars of chocolate they wanted to buy
  103. print("** ",beans1 + tuna1 + skittle1 + bar1," items bought in total **") ##prints the total amount of items they purchased
  104. print("Your final bill is: ") ##
  105. print(round(finalbill,2))##prints out the total amount of money they have to pay for the items they purchased to 2 decimal places
  106.  
  107. channel=open('List1.txt','w')
  108.  
  109.  
  110. valid=True ##ends program
  111. 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
  112. valid=False ##goes back to the stock
  113.  
  114. else: ##
  115. 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