Guest User

Untitled

a guest
May 28th, 2013
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. import time
  2. import sys
  3. import random
  4. x=0
  5. fcredit=0
  6. while x!=1:
  7. error1=True
  8. error2=True
  9. while error1==True:
  10. try:
  11. print"\n"
  12. print" +++++++++++++++++++++++++++++++++++++"
  13. print" ++!Welcome to RBDC Vending Machine!++"
  14. print" +++++++++++++++++++++++++++++++++++++"
  15. print" ***Build-1.2 FINAL***\n"
  16. print"***You need more than $0.50 to purchase any item***\n"
  17. print" ***Your Credit is $ %0.2f***\n"%fcredit
  18. a=float(input("How many 10p : $ "))
  19. b=float(input("How many 20p : $ "))
  20. c=float(input("How many 50p : $ "))
  21. d=float(input("How many £1 : $ "))
  22. print"\n"
  23. credit=(10*a)+(20*b)+(50*c)+(100*d)
  24. totalcredit=credit/100
  25. fcredit=fcredit+totalcredit
  26. if fcredit < 0.50:
  27. print"You don't have enough credit.\n***Enter more credit***\n"
  28. elif fcredit >= 0.50:
  29. print " ***Your credit now is $ %0.2f***"%fcredit
  30. print "\n"
  31. error1=False
  32. except NameError:
  33. print"Not a number. Please try again."
  34. time.sleep(1)
  35. except SyntaxError:
  36. print"Not a number. Please try again."
  37. time.sleep(1)
  38.  
  39. print"++!Welcome to RBDC Vending Machine!++\n"
  40. print" |*****************************|"
  41. print" |++ ++ +++++ ++ ++ ++ ++|"
  42. print" |+++ +++ + +++ ++ ++ ++|"
  43. print" |++ + ++ ++++ ++ + ++ ++ ++|"
  44. print" |++ ++ + ++ +++ ++ ++|"
  45. print" |++ ++ +++++ ++ ++ +++++ |"
  46. print" |*****************************|"
  47. print"\n"
  48. time.sleep(1)
  49. #generates a random number of stock for each item.
  50. coke = random.randrange(0,10)
  51. pepsi = random.randrange(0,6)
  52. walkers = random.randrange(0,15)
  53. snikers = random.randrange(0,12)
  54. mars = random.randrange(0,8)
  55. mountaindew = random.randrange(0,9)
  56.  
  57. print"1)*There are",coke,"Coca-Cola-$0.89"
  58. print"2)*There are",pepsi,"Pepsi-$0.79"
  59. print"3)*There are",walkers,"Walkers-Cheese & Onion-$0.49"
  60. print"4)*There are",snikers,"Snikers-$0.37"
  61. print"5)*There are",mars,"Mars-$0.34"
  62. print"6)*There are",mountaindew,"Mountain Dew-$0.79\n"
  63. print"***Your credit is $ %0.2f"%fcredit,"***\n"
  64.  
  65. while error2==True:
  66. try:
  67. vending=input("Select a Option: ")
  68. if vending >= 7:
  69. print"Enter a number between 1-6. Please try again."
  70. elif vending==0:
  71. print"Enter a number between 1-6. Please try again."
  72. error2=False
  73. else:
  74. print"Enter a number between 1-6. Please try again."
  75. except NameError:
  76. print"Enter a number between 1-6. Please try again."
  77. time.sleep(1)
  78. except SyntaxError:
  79. print"Enter a number between 1-6. Please try again."
  80. time.sleep(1)
  81.  
  82.  
  83. if vending==1:
  84. if coke ==0:#checks for stock
  85. print"This item is currently unavailable.\nYour credit is %0.2f"%fcredit
  86. time.sleep(1)
  87. elif fcredit < 0.89:#checks if there is enough credit to buy this item.
  88. print"You don't have enough credit to purchase this item."
  89. print"Your credit is %0.2f"%fcredit
  90. elif coke >=1:#checks if coke is more than 0.
  91. print"You have chosen to despence a Coke can."
  92. blah = "..."
  93. for l in blah:
  94. sys.stdout.write(l)
  95. sys.stdout.flush()
  96. time.sleep(1.2)
  97. fcredit=fcredit-0.89
  98. print"\nChange due is $ %0.2f"%fcredit
  99. print"\n"
  100. time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment