Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rates = {
- "apples" : 5.3,
- "bananas" : 1.2,
- "cereal" : 6.7,
- "grapes" : 4.5,
- "ice cream" : 11.4,
- "jelly" : 2.3,
- "kiwi" : 7.6,
- "oranges" : 3.3
- }
- #using for loop
- n = int(input("enter total itmes bought"))
- quantities={}
- for i in range(n):
- keys = input() # here i have taken keys as strings
- values = int(input()) # here i have taken values as integers
- quantities[keys] = values
- #using while loop
- abc = "yes"
- while abc!="no":
- keys = input("enter product bought")
- values = int(input("quantity"))
- quantities[keys]=values
- abc = input("add more products? yes/no")
- #using function
- def grocerylist(keys, values):
- quantities[keys] = values
- def compute_bill(a):
- total = 0
- for item, quantity in a.items():
- total += rates[item]*quantity
- return total
- print(compute_bill(quantities))
Add Comment
Please, Sign In to add comment