Advertisement
Guest User

Untitled

a guest
May 4th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.06 KB | None | 0 0
  1. import math #this allows functions using maths to be used later on within the program
  2. def end(credit):#defines the program
  3.     print("dispense change:",credit,"p")
  4.     print("Goodbye")
  5. def choices(credit):#defines the program
  6.     print("")#spacing for better structure
  7.     print('you can choose from the products below')#tells user that they can choose from a list of products
  8.     print("1.Water-50p")#choice 1 out of 5. 5 other choices are mentioned below. Also tells the user how much the products cost
  9.     print("2.Yoghurt-100p")
  10.     print("3.Chocolate-120p")
  11.     print("4.Coke-160p")
  12.     print("5.crisps-70p")
  13.     print("You have",credit,"p")#tells the user how much credit they currently have
  14.     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
  15.     water=50
  16.     yoghurt=70
  17.     wasabi=100
  18.     chocolate=120
  19.     coke=160
  20.     crisps=70
  21.     if choice=1:#if statement:if choice is 1 then it will lead to (mentioned below)
  22.         print("you have picked a water that is 50p")#lets the user know they have picked the item corresponding with the number the inputted
  23.         pricecheck=credit-water#variable 'pricecheck' takes away the item value from the credit
  24.         if pricecheck<0:#if the 'pricecheck' is lower than 0, it shows that the user does not have enough
  25.             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
  26.  
  27.         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
  28.             credit=credit-water#variable 'credit' takes away water from credit
  29.             print("")
  30.             print("Dispense water")#dispenses water on the basis of the aforementioned else statement
  31.             print("you have",credit,"p left")#tells you how much credit you have left
  32.  
  33.     elif choice==2:
  34.         print("you have picked a yoghurt worth 100p")# **same process as previous item.
  35.         pricecheck=credit-yoghurt
  36.         if pricecheck<0:
  37.             print("you don't have enough money")
  38.  
  39.         else:
  40.             credit=credit-yoghurt
  41.             print("")
  42.             print("Dispense yoghurt")
  43.             print("you have",credit,"p left")
  44.  
  45.     elif choice==3:
  46.         print("you have picked a chocolate worth 120p")
  47.         pricecheck=credit-chocolate
  48.         if pricecheck<0:
  49.             print("you don't have enough money")
  50.  
  51.         else:
  52.             credit=credit-chocolate
  53.             print("")
  54.             print("Dispense chocolate")
  55.             print("you have",credit,"p left")
  56.  
  57.     elif choice==4:
  58.         print("you have picked a Coke worth 160p")
  59.         pricecheck=credit-coke
  60.         if pricecheck<0:
  61.             print("you don't have enough money")
  62.  
  63.         else:
  64.             credit=credit-coke
  65.             print("")
  66.             print("Dispense Coke")
  67.             print("you have",credit,"p left")
  68.  
  69.     elif choice==5:
  70.         print("you have picked crisps worth 70")
  71.         pricecheck=credit-crisps
  72.         if pricecheck<0:
  73.             print("you don't have enough money")
  74.  
  75.         else:
  76.             credit=credit-crisps
  77.             print("")
  78.             print("Dispense crisps")
  79.             print("you have",credit,"p left")# **same process of tasks ends here
  80.  
  81.  
  82.     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.
  83.    
  84.     if newcredit==1:#if the choice of 'newcredit' is 1...
  85.         balancee(credit)#lets the user input more credit
  86.                
  87.     elif newcredit == 2:#if the choice of 'newcredit' is 2...
  88.         choices(credit)#loops back to choices as user wants to buy another item
  89.  
  90.     elif newcredit == 3:#if the choice of 'newcredit' is 3...
  91.         end(credit)#ends the program
  92.        
  93.        
  94.        
  95. def balancee(credit):#defines the mentioned 'creditz'
  96.     response=int(1)# response is integer 1
  97.     while response==1:#while loop which is continuous. whenever user inputs 1 the following will occur...
  98.         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.
  99.         credit=credit+coins#adds on the new credit you inputted
  100.         print("your current credit is:",credit,"p")#prints your new credit. will always update it.
  101.         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
  102.        
  103.     choices(credit)
  104.  
  105.                
  106.            
  107.    
  108. def vending_machine():
  109.     print("welcome to the vending machine!!!")
  110.     print("currently you have no credit.")
  111.     credit=int(0)
  112.     balancee(credit)
  113.                
  114. vending_machine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement