Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import os
- #stock list with names, prices and the corrosponding id
- items = [("chocolate", "1.50", "1"), ("crisps", "0.75", "2"), ("lemonade", "1", "3")]
- #def isIdValid(id):
- # ids = []
- # for i in range(len(items)):
- # ids.append(int(items[i][2]))
- # if id not in ids:
- # return False
- # return True
- #checks if the id is valid
- def isIdValid2(id):
- found=False
- for i in range(len(items)):
- if int(items[i][2])==id:
- found=True
- break
- return found
- #checks to see if a number is a number
- def checktype(id):
- try:
- int(id)
- return True
- except ValueError:
- return False
- #main function
- def ask():
- #lists the available items
- for i in range(len(items)):
- print("Item " + items[i][2] + ": " + items[i][0] + " : £" + items[i][1])
- print("select the item id you would wish to purchase from the list above")
- id = input()
- #checks the input and acts accordingly
- if checktype(id) == False:
- os.system('cls')
- print("you did not enter a number retry")
- time.sleep(1.5)
- os.system('cls')
- return
- else:
- id=int(id)
- if isIdValid2(id) == False:
- os.system('cls')
- print("please enter an id in the list")
- time.sleep(1.5)
- os.system('cls')
- return
- print("processing")
- time.sleep(1)
- os.system('cls')
- print("you have selected " + items[int(id) - 1][0] + " this will cost £" + items[int(id) - 1][1] + " please insert the required money")
- print("*how much money do you put in?*")
- paid = input()
- if float(paid) > float(items[int(id) - 1][1]) :
- change = round(float(paid) - float(items[int(id) - 1][1]), 3)
- print("we are dispensing your " + items[int(id) - 1][0] + " and providing you with £" + str(change) + " as change.")
- print("dispensing " + items[int(id) - 1][0])
- time.sleep(2)
- print("dispensing change")
- time.sleep(2)
- print("thanks for shopping with us")
- time.sleep(3)
- os.system('cls')
- return
- if float(paid) == round(float(items[int(id) - 1][1]), 3):
- print("we are dispensing your " + items[int(id) - 1][0])
- time.sleep(2)
- print("thanks for shopping with us")
- time.sleep(3)
- os.system('cls')
- if float(paid) < round(float(items[int(id) - 1][1]), 3):
- 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)))
- print("please pay the remaining amount")
- while float(paid) < round(float(items[int(id) - 1][1]), 3):
- amt = input()
- amt = round(float(amt), 3)
- paid = float(paid)
- paid += amt
- topay = round(float(items[int(id) - 1][1]), 3) - paid
- topay = round(topay, 3)
- if float(paid) < round(float(items[int(id) - 1][1]), 3):
- print("you still need to insert £" + str(topay))
- if float(paid) > float(items[int(id) - 1][1]):
- change = round(float(paid) - float(items[int(id) - 1][1]), 3)
- print("we are dispensing your " + items[int(id) - 1][0] + " and providing you with £" + str(change) + " as change.")
- print("dispensing " + items[int(id) - 1][0])
- time.sleep(2)
- print("dispensing change")
- time.sleep(2)
- print("thanks for shopping with us")
- time.sleep(3)
- os.system('cls')
- return
- print("we are dispensing your " + items[int(id) - 1][0])
- time.sleep(2)
- print("thanks for shopping with us")
- time.sleep(3)
- os.system('cls')
- while True:
- ask()
Add Comment
Please, Sign In to add comment