Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import sys
- import random
- x=0
- fcredit=0
- while x!=1:
- error1=True
- error2=True
- while error1==True:
- try:
- print"\n"
- print" +++++++++++++++++++++++++++++++++++++"
- print" ++!Welcome to RBDC Vending Machine!++"
- print" +++++++++++++++++++++++++++++++++++++"
- print" ***Build-1.2 FINAL***\n"
- print"***You need more than $0.50 to purchase any item***\n"
- print" ***Your Credit is $ %0.2f***\n"%fcredit
- a=float(input("How many 10p : $ "))
- b=float(input("How many 20p : $ "))
- c=float(input("How many 50p : $ "))
- d=float(input("How many £1 : $ "))
- print"\n"
- credit=(10*a)+(20*b)+(50*c)+(100*d)
- totalcredit=credit/100
- fcredit=fcredit+totalcredit
- if fcredit < 0.50:
- print"You don't have enough credit.\n***Enter more credit***\n"
- elif fcredit >= 0.50:
- print " ***Your credit now is $ %0.2f***"%fcredit
- print "\n"
- error1=False
- except NameError:
- print"Not a number. Please try again."
- time.sleep(1)
- except SyntaxError:
- print"Not a number. Please try again."
- time.sleep(1)
- print"++!Welcome to RBDC Vending Machine!++\n"
- print" |*****************************|"
- print" |++ ++ +++++ ++ ++ ++ ++|"
- print" |+++ +++ + +++ ++ ++ ++|"
- print" |++ + ++ ++++ ++ + ++ ++ ++|"
- print" |++ ++ + ++ +++ ++ ++|"
- print" |++ ++ +++++ ++ ++ +++++ |"
- print" |*****************************|"
- print"\n"
- time.sleep(1)
- #generates a random number of stock for each item.
- coke = random.randrange(0,10)
- pepsi = random.randrange(0,6)
- walkers = random.randrange(0,15)
- snikers = random.randrange(0,12)
- mars = random.randrange(0,8)
- mountaindew = random.randrange(0,9)
- print"1)*There are",coke,"Coca-Cola-$0.89"
- print"2)*There are",pepsi,"Pepsi-$0.79"
- print"3)*There are",walkers,"Walkers-Cheese & Onion-$0.49"
- print"4)*There are",snikers,"Snikers-$0.37"
- print"5)*There are",mars,"Mars-$0.34"
- print"6)*There are",mountaindew,"Mountain Dew-$0.79\n"
- print"***Your credit is $ %0.2f"%fcredit,"***\n"
- while error2==True:
- try:
- vending=input("Select a Option: ")
- if vending >= 7:
- print"Enter a number between 1-6. Please try again."
- elif vending==0:
- print"Enter a number between 1-6. Please try again."
- error2=False
- else:
- print"Enter a number between 1-6. Please try again."
- except NameError:
- print"Enter a number between 1-6. Please try again."
- time.sleep(1)
- except SyntaxError:
- print"Enter a number between 1-6. Please try again."
- time.sleep(1)
- if vending==1:
- if coke ==0:#checks for stock
- print"This item is currently unavailable.\nYour credit is %0.2f"%fcredit
- time.sleep(1)
- elif fcredit < 0.89:#checks if there is enough credit to buy this item.
- print"You don't have enough credit to purchase this item."
- print"Your credit is %0.2f"%fcredit
- elif coke >=1:#checks if coke is more than 0.
- print"You have chosen to despence a Coke can."
- blah = "..."
- for l in blah:
- sys.stdout.write(l)
- sys.stdout.flush()
- time.sleep(1.2)
- fcredit=fcredit-0.89
- print"\nChange due is $ %0.2f"%fcredit
- print"\n"
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment