1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
abruzzese [7]
3 years ago
13

g 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. Kee

p 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. For this discussion, you should first write pseudocode for how you would solve this problem (reference pseudocode.py in the Week 7 Coding Tutorials section for an example). Then write the code for how you would tackle this function. Please submit a Python file called rocks_discussion.py that defines the function (code) and calls it in main().
Computers and Technology
1 answer:
Scilla [17]3 years ago
4 0

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

You might be interested in
________ use statistics to anticipate customers withdrawals. ________ use statistic to calculate probable life expectancy to hel
Fudgin [204]

Answer:

Banks

Insurance companies

Explanation:

3 0
3 years ago
Read the two sentences below. Then select the response that best describes the verb tense used in the sentences.
N76 [4]
I would say A because it was talking about something in the present but what they were talking about was in past. so I would think A
6 0
3 years ago
B) Explain in detail the three technologies commonly used in display
wlad13 [49]

Answer:

b i think

Explanation:

5 0
3 years ago
What is the purpose of the domain name? The domain name is an example of a service provider. The domain name .gov.nz is an examp
malfutka [58]

.gov.nz is for New Zealand

6 0
3 years ago
Read 2 more answers
Jaden needs to implement a telecommunications technology that would most improve the way members of his team exchange informatio
Verdich [7]
<span>The fact that Jaden uses decision-making strategy means that he</span><span><span> will make his decision based on long-term goals and a longer term vision.</span> In order to implement a telecommunication technology that would most improve the way members of his team exchange information, Jaden first must determine the goals. </span>

3 0
3 years ago
Other questions:
  • What does Verizon child allow parents to do? My parents recently got the app and put it on my phone so I was wondering...
    11·1 answer
  • True or false the primary advantage of the worksheet is the ability to solve numerical problems quickly and accurately
    11·1 answer
  • 10.
    13·1 answer
  • Which type of text may be formatted to print at the bottom of every page?
    6·1 answer
  • What is a IT form? any help would be great thnx
    14·2 answers
  • What is wrong with line 1?
    14·1 answer
  • * Create a list of places and situations in which we use a computer
    11·1 answer
  • 2. What is the name for an action performed by the VR Robot?
    7·2 answers
  • Describe how to find and replace a text in a document​
    13·1 answer
  • Which term refers to a shorthand method for identifying network and host bits in an ip address?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!