Input:
List
Example Output:
Would you like to list info about all the fruits we offer here, or buy a fruit?
This is all of the fruits we have, and their color
apple : red
lemon : yellow
orange : orange
kiwi : green
blueberry : blue
plum : purple
Code Associated:
Lines 1-8:
This creates a dictionary with 6 different types of fruits, and maps them to a color to be printed later
Lines 20-21:
This prints a question, then takes the input afterwards
Lines 44-47:
This accounts for capitals in the input to avoid case sensitivity and checks if the user inputted the string “list”, then prints a text, and loops through the items in the dictionary, the keys getting bound to a variable named item, and the values getting bound to a variable named value, then prints them out later.
Input:
buy
Example Output:
This is what we have for mainly sweet fruits:
apple
orange
blueberry
plum
This is what we have for more sour fruits:
lemon
kiwi
This is the cost of all the fruits in shekels, and blueberries are sold in batches of 150:
apple : 10
lemon : 15
orange : 30
honeydew : 80
blueberry : 20
plum : 35
You have bought 10 Apple(s) for 100 money.
Code Associated:
Lines 9-43:
Defines dictionary for cost, lists for sweet/sour fruit and fruits, asks a question and waits for an input, then tests if the lowercase input is “buy”. After this, it prints out the sour fruits under one section with one for loop which looks for fruits in the list fruits that are also in the list sour, and then prints out the sweet fruits under another section with one for loop which looks for fruits which are in both sweet and fruit lists. Then, it prints out the costs using the dictionary, using item for the key, and value for the value. Then, it takes an input from the user and asks what fruit they would like to buy, and checks if that is a valid response. Then, it asks how many for the cost calculation, multiplying the amount by 150 if the input is “blueberries”. Then, it calculates the cost using the amount the user inputted, and multiplies it by the cost of the fruit from the input that the user put. Then, it prints out what you bought, how many, and for how much.
Example Input:
Hi
Output:
elif option.lower() not in [“buy”, “list”]:
print(“Sorry, this input is not accepted.”)
Code Associated:
Lines 44-45:
Checks if the first input the user puts in is not buy or list, and gives a message before the program stops running.