Guest User

Untitled

a guest
Sep 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. import time
  2. import os
  3. #stock list with names, prices and the corrosponding id
  4. items = [("chocolate", "1.50", "1"), ("crisps", "0.75", "2"), ("lemonade", "1", "3")]
  5.  
  6. #def isIdValid(id):
  7. # ids = []
  8. # for i in range(len(items)):
  9. # ids.append(int(items[i][2]))
  10. # if id not in ids:
  11. # return False
  12. # return True
  13.  
  14. #checks if the id is valid
  15. def isIdValid2(id):
  16. found=False
  17. for i in range(len(items)):
  18. if int(items[i][2])==id:
  19. found=True
  20. break
  21. return found
  22. #checks to see if a number is a number
  23. def checktype(id):
  24. try:
  25. int(id)
  26. return True
  27. except ValueError:
  28. return False
  29. #main function
  30. def ask():
  31. #lists the available items
  32. for i in range(len(items)):
  33. print("Item " + items[i][2] + ": " + items[i][0] + " : £" + items[i][1])
  34. print("select the item id you would wish to purchase from the list above")
  35. id = input()
  36. #checks the input and acts accordingly
  37. if checktype(id) == False:
  38. os.system('cls')
  39. print("you did not enter a number retry")
  40. time.sleep(1.5)
  41. os.system('cls')
  42. return
  43. else:
  44. id=int(id)
  45. if isIdValid2(id) == False:
  46. os.system('cls')
  47. print("please enter an id in the list")
  48. time.sleep(1.5)
  49. os.system('cls')
  50. return
  51. print("processing")
  52. time.sleep(1)
  53. os.system('cls')
  54. print("you have selected " + items[int(id) - 1][0] + " this will cost £" + items[int(id) - 1][1] + " please insert the required money")
  55. print("*how much money do you put in?*")
  56. paid = input()
  57. if float(paid) > float(items[int(id) - 1][1]) :
  58. change = round(float(paid) - float(items[int(id) - 1][1]), 3)
  59. print("we are dispensing your " + items[int(id) - 1][0] + " and providing you with £" + str(change) + " as change.")
  60. print("dispensing " + items[int(id) - 1][0])
  61. time.sleep(2)
  62. print("dispensing change")
  63. time.sleep(2)
  64. print("thanks for shopping with us")
  65. time.sleep(3)
  66. os.system('cls')
  67. return
  68. if float(paid) == round(float(items[int(id) - 1][1]), 3):
  69. print("we are dispensing your " + items[int(id) - 1][0])
  70. time.sleep(2)
  71. print("thanks for shopping with us")
  72. time.sleep(3)
  73. os.system('cls')
  74. if float(paid) < round(float(items[int(id) - 1][1]), 3):
  75. print("you inserted £" + str(paid) + " however the cost is £" + str(items[int(id) - 1][1]) + " so you need to pay an extra £" + str(round(float(items[int(id) - 1][1]), 3) - float(paid)))
  76. print("please pay the remaining amount")
  77. while float(paid) < round(float(items[int(id) - 1][1]), 3):
  78. amt = input()
  79. amt = round(float(amt), 3)
  80. paid = float(paid)
  81. paid += amt
  82. topay = round(float(items[int(id) - 1][1]), 3) - paid
  83. topay = round(topay, 3)
  84. if float(paid) < round(float(items[int(id) - 1][1]), 3):
  85. print("you still need to insert £" + str(topay))
  86. if float(paid) > float(items[int(id) - 1][1]):
  87. change = round(float(paid) - float(items[int(id) - 1][1]), 3)
  88. print("we are dispensing your " + items[int(id) - 1][0] + " and providing you with £" + str(change) + " as change.")
  89. print("dispensing " + items[int(id) - 1][0])
  90. time.sleep(2)
  91. print("dispensing change")
  92. time.sleep(2)
  93. print("thanks for shopping with us")
  94. time.sleep(3)
  95. os.system('cls')
  96. return
  97. print("we are dispensing your " + items[int(id) - 1][0])
  98. time.sleep(2)
  99. print("thanks for shopping with us")
  100. time.sleep(3)
  101. os.system('cls')
  102.  
  103.  
  104.  
  105. while True:
  106. ask()
Add Comment
Please, Sign In to add comment