Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math #this allows functions using maths to be used later on within the program
- def end(credit):#defines the program
- print("dispense change:",credit,"p")
- print("Goodbye")
- def choices(credit):#defines the program
- print("")#spacing for better structure
- print('you can choose from the products below')#tells user that they can choose from a list of products
- print("1.Water-50p")#choice 1 out of 5. 5 other choices are mentioned below. Also tells the user how much the products cost
- print("2.Yoghurt-100p")
- print("3.Chocolate-120p")
- print("4.Coke-160p")
- print("5.crisps-70p")
- print("You have",credit,"p")#tells the user how much credit they currently have
- choice=int(input("would you like product 1,2,3,4,5"))#this is where the choice is made for the user to buy a product
- water=50
- yoghurt=70
- wasabi=100
- chocolate=120
- coke=160
- crisps=70
- if choice=1:#if statement:if choice is 1 then it will lead to (mentioned below)
- print("you have picked a water that is 50p")#lets the user know they have picked the item corresponding with the number the inputted
- pricecheck=credit-water#variable 'pricecheck' takes away the item value from the credit
- if pricecheck<0:#if the 'pricecheck' is lower than 0, it shows that the user does not have enough
- print("you don't have enough money")#on the basis of the price check, it will tell the user they do not have enough money
- else:#if the credit is something else it shows that it is not below 0, thus meaning that it had to have been the case that the user had enough money on their balance
- credit=credit-water#variable 'credit' takes away water from credit
- print("")
- print("Dispense water")#dispenses water on the basis of the aforementioned else statement
- print("you have",credit,"p left")#tells you how much credit you have left
- elif choice==2:
- print("you have picked a yoghurt worth 100p")# **same process as previous item.
- pricecheck=credit-yoghurt
- if pricecheck<0:
- print("you don't have enough money")
- else:
- credit=credit-yoghurt
- print("")
- print("Dispense yoghurt")
- print("you have",credit,"p left")
- elif choice==3:
- print("you have picked a chocolate worth 120p")
- pricecheck=credit-chocolate
- if pricecheck<0:
- print("you don't have enough money")
- else:
- credit=credit-chocolate
- print("")
- print("Dispense chocolate")
- print("you have",credit,"p left")
- elif choice==4:
- print("you have picked a Coke worth 160p")
- pricecheck=credit-coke
- if pricecheck<0:
- print("you don't have enough money")
- else:
- credit=credit-coke
- print("")
- print("Dispense Coke")
- print("you have",credit,"p left")
- elif choice==5:
- print("you have picked crisps worth 70")
- pricecheck=credit-crisps
- if pricecheck<0:
- print("you don't have enough money")
- else:
- credit=credit-crisps
- print("")
- print("Dispense crisps")
- print("you have",credit,"p left")# **same process of tasks ends here
- newcredit=int(input("To input more credit enter 1, to buy another item enter 2, to dipense your goods and collect your change enter 3:"))#variable 'newcredit' gives the user 3 options on what they would like to do.
- if newcredit==1:#if the choice of 'newcredit' is 1...
- balancee(credit)#lets the user input more credit
- elif newcredit == 2:#if the choice of 'newcredit' is 2...
- choices(credit)#loops back to choices as user wants to buy another item
- elif newcredit == 3:#if the choice of 'newcredit' is 3...
- end(credit)#ends the program
- def balancee(credit):#defines the mentioned 'creditz'
- response=int(1)# response is integer 1
- while response==1:#while loop which is continuous. whenever user inputs 1 the following will occur...
- coins=int(input("Enter a single coin:10p=10 20p=20 50p=50 £1=100:"))#you can make your choice on the basis of the 'response' variable. 'coins' represents the new credit entered each time.
- credit=credit+coins#adds on the new credit you inputted
- print("your current credit is:",credit,"p")#prints your new credit. will always update it.
- response=int(input("If you would like to put in more coins- enter 1 for yes and 2 for no"))#lets the user make another choice. if choice is 1, it will loop back to the while loop, ultimately leading back to this choice again. this allows the user to buy as many items as possible
- choices(credit)
- def vending_machine():
- print("welcome to the vending machine!!!")
- print("currently you have no credit.")
- credit=int(0)
- balancee(credit)
- vending_machine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement