Arcot

ch8 ex3

Dec 9th, 2021 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. rates = {
  2. "apples" : 5.3,
  3. "bananas" : 1.2,
  4. "cereal" : 6.7,
  5. "grapes" : 4.5,
  6. "ice cream" : 11.4,
  7. "jelly" : 2.3,
  8. "kiwi" : 7.6,
  9. "oranges" : 3.3
  10. }
  11. #using for loop
  12. n = int(input("enter total itmes bought"))
  13. quantities={}
  14.  
  15. for i in range(n):
  16.     keys = input() # here i have taken keys as strings
  17.     values = int(input()) # here i have taken values as integers
  18.     quantities[keys] = values
  19.  
  20. #using while loop
  21. abc = "yes"
  22. while abc!="no":
  23.     keys = input("enter product bought")
  24.     values = int(input("quantity"))
  25.     quantities[keys]=values
  26.     abc = input("add more products? yes/no")
  27.  
  28. #using function
  29. def grocerylist(keys, values):
  30.     quantities[keys] = values
  31.  
  32. def compute_bill(a):
  33.     total = 0
  34.     for item, quantity in a.items():
  35.         total += rates[item]*quantity
  36.     return total
  37. print(compute_bill(quantities))
Add Comment
Please, Sign In to add comment