In: Computer Science
Write a function called price_of_rocks. It has no parameters. In a while loop, get a rock type and a weight from the user. Keep a running total of the price for all requested rocks. Repeat until the user wants to quit. Quartz crystals cost $23 per pound. Garnets cost $160 per pound. Meteorite costs $15.50 per gram. Assume the user enters weights in the units as above. Return the total price of all of the material. Using Python
For this discussion, you should first write pseudocode for how you would solve this problem
Please write the Pseudocode for this problem.
// PSEUDOCODE//
procedure getPrice(type, weight)
if (type = 'Quartz crystal')
then return 23 * weight
else if (type = 'Garnet') then
return 160 * weight
else if (type = 'Meteorite')
return 15.5 * weight
end getPrice
procedure getUnit(type)
if (type = 'Quartz crystal')
then return 'pound'
else if (type = 'Garnet') then
return 'pound'
else if (type = 'Meteorite')
return 'gram'
end getUnit
procedure price_of_rocks()
declare double total_cost <-- 0
yesOrNo <-- 'Y'
while (yesOrNo = 'Y' OR yesOrNo = 'y') do
type <--input("Enter Rock type : ")
weight <-- input("Enter Weight ( " + getUnit(type) + " ) : ")
total_cost <-- total_cost + getPrice(type, weight)
YesOrNo <-- input("Do You wish to Continue(Y/N) : ")
end while
return total_cost
end price_of_rocks