Answer:
<u>The pseudocode:</u>
FUNCTION price_of_rocks():
SET total = 0
while True:
INPUT rock_type
INPUT weight
if rock_type is "Quartz crystals":
SET total += weight * 23
elif rock_type is "Garnets":
SET total += weight * 160
elif rock_type is "Meteorite":
SET total += weight * 15.50
INPUT choice
if choice is "n":
break
RETURN total
END FUNCTION
<u>The code:</u>
def price_of_rocks():
total = 0
while True:
rock_type = input("Enter rock type: ")
weight = float(input("Enter weight: "))
if rock_type == "Quartz crystals":
total += weight * 23
elif rock_type == "Garnets":
total += weight * 160
elif rock_type == "Meteorite":
total += weight * 15.50
choice = input("Continue? (y/n) ")
if choice == "n":
break
return total
print(price_of_rocks())
Explanation:
Create a function named price_of_rocks that does not take any parameters
Initialize the total as 0
Create an indefinite while loop. Inside the loop:
Ask the user to enter the rock_type and weight
Check the rock_type. If it is "Quartz crystals", multiply weight by 23 and add it to the total (cumulative sum). If it is "Garnets", multiply weight by 160 and add it to the total (cumulative sum). If it is "Meteorite", multiply weight by 15.50 and add it to the total (cumulative sum).
Then, ask the user to continue or not. If s/he enters "n", stop the loop.
At the end of function return the total
In the main, call the price_of_rocks and print