livepython.net

113. Python Program to Calculate a Fruit Bill

MediumRead values

Overview

Combine a dictionary lookup with in, if and the string methods of chapter 12.

Problem Statement

The shop's prices are already in the starter code:

prices = {"apple": 40, "banana": 10, "mango": 60, "kiwi": 25}

Read a fruit name, then a quantity (a whole number). The name may have capital letters or spaces around it, so clean it first: " Mango " means mango. If the shop sells the fruit, print the total in the format Total: 120. If not, print Sorry, we don't sell and the cleaned name, like Sorry, we don't sell grapes. For example, for apple and 3:

Total: 120

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One value per line, in this order. Example:

apple
3

Output

The output for that example:

Total: 120

The tests try 4 different inputs.

Learn this firstChapter 13 · Access Dictionary Values in Python: [], get() and in
solution.py
prices = {"apple": 40, "banana": 10, "mango": 60, "kiwi": 25}
# write your code here

EXPECTED OUTPUT

1Total: 120

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.