SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. money = input('Total money: ')
  4. mi = int(money)
  5.  
  6. Food = ['Taco', 'Burrito', 'Nacho']
  7. Price = [6, 4, 2]
  8. Dict = {f:p for (f, p) in zip(Food, Price)}
  9.  
  10. while mi >= 0:
  11.     RFS = random.sample(Food, 1)[0]
  12.     cost = Dict[RFS]
  13.     mi = mi - cost
  14.     print("item: {} cost: {} money you have: {} ".format(RFS,cost,mi))
  15.      
  16. import random
  17.  
  18. money = int(input('Total money: '))
  19.  
  20. Food = ['Taco', 'Burrito', 'Nacho']
  21. Price = [6, 4, 2]
  22. Dict = {f:p for (f, p) in zip(Food, Price)}
  23. Purchases = {f:0 for f in Dict}
  24.  
  25. stop = False
  26. while not stop:
  27.     for i in Dict:
  28.         cost = Dict[i]
  29.         if money - cost < 0:
  30.             stop = True
  31.             break
  32.         else:
  33.             money -= cost
  34.             Purchases[i] += 1
  35.  
  36. print(Purchases)
  37.      
  38. import random
  39.  
  40. money = input('Total money: ')
  41. mi = int(money)
  42.  
  43. Food = ['Taco', 'Burrito', 'Nacho']
  44. Price = [6, 4, 2]
  45. Dict = {f:p for (f, p) in zip(Food, Price)}
  46.  
  47. totals = {'Taco': 0, 'Burrito': 0, 'Nacho': 0, 'Change': 0}
  48.  
  49. while mi > 0:
  50.     RFS = random.sample(Food, 1)[0]
  51.     cost = Dict[RFS]
  52.     if cost <= mi:
  53.         mi += - cost
  54.         print("item: {} cost: {} money you have: {} ".format(RFS, cost, mi))
  55.         totals[RFS] += 1
  56.     elif all(i > mi for i in Price):
  57.         totals['Change'] = mi
  58.         break
  59.  
  60. print(totals)
  61.      
  62. Total money: 11
  63. item: Nacho cost: 2 money you have: 9
  64. item: Taco cost: 6 money you have: 3
  65. item: Nacho cost: 2 money you have: 1
  66. {'Taco': 1, 'Burrito': 0, 'Nacho': 2, 'Change': 1}
  67.      
  68. from collections import Counter
  69. money = input('Total money: ')
  70. mi = int(money)
  71. Food = ['Taco', 'Burrito', 'Nacho']
  72. Price = [6, 4, 2]
  73. Dict = {f:p for (f, p) in zip(Food, Price)}
  74. purchase_ls = []
  75. while mi >= min(Price):    
  76.     for aFood in Food:
  77.         if mi < int(Price[Food.index(aFood)]):
  78.             continue
  79.         purchase_ls.append(aFood)
  80.         cost = int(Price[Food.index(aFood)])
  81.         mi = mi - cost
  82.         print("item: {} cost: {} money you have: {} ".format(aFood,cost,mi))  
  83.         if mi <= 0:
  84.             break        
  85. print(dict(Counter(purchase_ls)))
  86.      
  87. Total money: 22
  88. item: Taco cost: 6 money you have: 16
  89. item: Burrito cost: 4 money you have: 12
  90. item: Nacho cost: 2 money you have: 10
  91. item: Taco cost: 6 money you have: 4
  92. item: Burrito cost: 4 money you have: 0
  93. {'Taco': 2, 'Burrito': 2, 'Nacho': 1}
  94.  
  95. Total money: 20
  96. item: Taco cost: 6 money you have: 14
  97. item: Burrito cost: 4 money you have: 10
  98. item: Nacho cost: 2 money you have: 8
  99. item: Taco cost: 6 money you have: 2
  100. item: Nacho cost: 2 money you have: 0
  101. {'Taco': 2, 'Burrito': 1, 'Nacho': 2}
  102.  
  103. Total money: 10
  104. item: Taco cost: 6 money you have: 4
  105. item: Burrito cost: 4 money you have: 0
  106. {'Taco': 1, 'Burrito': 1}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top