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
The computers in the administrative offices of the four schools throughout the district are networked to enable employees to acc
muminat
These computers in administrative offices or schools throughout the district that are networked to each other has the type of network most likely used by the workers is LAN network. Usually LAN networks are used in small offices or rooms.
3 0
4 years ago
A _______ is used to analyze and summarize your data without graphical support
kkurt [141]
<span>A Pivot table is used to analyze and summarize your data without graphical support</span>
3 0
4 years ago
Read 2 more answers
What is true about music from the Romantic period?
avanturin [10]
The answer to the given question above is the third option: <span>It was longer and less constrained than the music of the Classical period. The Romantic Period in music actually has more freedom in design and form. During this period, music were even more artistic and intellectual as well. Romantic Period occurred the late 18th century until early 19th century.</span>
8 0
3 years ago
Read 2 more answers
I need this answer right away!
Degger [83]

Answer:

Foundation.

Bootstrap. 2.1 Resources.

Metro UI.

jQuery Mobile.

Sencha Touch.

Ionic.

HTML KickStart.

Semantic UI

Explanation:

5 0
3 years ago
Comment suprimer son compte brainly
Andru [333]
L'option de suppression de votre compte se trouve dans les Paramètres de votre Profil, sous la rubrique Privé. De là, vous devrez cliquer sur la case intitulée Je veux supprimer mon compte, et la demande de suppression sera envoyée
5 0
3 years ago
Other questions:
  • A pacing calendar is provided to students so they can:
    8·2 answers
  • A(n) __________ is a popular way to describe relationships? (i.e., one-to-one,? one-to-many) in a relational database.
    14·1 answer
  • ____ is designed for short-distance connections and has only a few lambdas, with a greater space between lambdas. Group of answe
    9·2 answers
  • When seeking information on the internet the most helpful place to look is?
    14·2 answers
  • Assume that name and age have been declared suitably for storing names (like "Abdullah", "Alexandra" and "Zoe") and ages respect
    5·1 answer
  • What does aux stand for on a car remote?
    13·2 answers
  • After pushing the power switch of the PC to the ʺonʺ position, Bob, the PC repair person, realizes that the power-on lights foun
    8·1 answer
  • What is the best way to set up the spreadsheet? List each expense in a row. List each income source in a column. List each expen
    15·2 answers
  • Which of the following players is on offence
    9·1 answer
  • Which tab do you open to access the Comments feature?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!