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
A gui allows you to interact with objects on the screen such as icons and buttons true or false
Alja [10]

Answer:

True

Explanation:

7 0
3 years ago
WILL CHOOSE BRAINLIEST! in cells D6 through D8, enter formulas to calculate the values of the stocks. The formulas should multip
gtnhenbr [62]

Answer:

Alice Grant has been saving and investing part of her salary for several years. She decides to keep track of her investments on a worksheet. The file Application 9-7 contains the investments of Alice Grant. She owns several types of investments:

Explanation:

8 0
2 years ago
What is a leased line​
scoundrel [369]

Explanation:

A leased line is a dedicated fixed bandwidth data connection. The word leased refers to the connection rented by the internet service provider directly to a business. A leased line needs to be symmetrical, uncontended and point to point

3 0
3 years ago
Read 2 more answers
Vector graphic is usually required more storage space than bit maps true or false
barxatty [35]
The answer is false
5 0
3 years ago
Is EXE is the extension of MS Excel file.<br> subject: ICT for GR 5
Tju [1.3M]

Answer:

.EXE is not an extension of MS Excel File.  The extention of MS Excel files are:

.xlsx         Excel workbook

.xlsm Excel macro-enabled workbook

.xlsb Excel binary workbook

.xltx         Excel template

Explanation:

3 0
3 years ago
Other questions:
  • TO COMPUTING IN BUSINE
    14·1 answer
  • What is a organisation in office technology
    7·1 answer
  • On what level has social media connected us to one another?
    11·1 answer
  • A ________ separates traditional voice telephone transmission from the data transmissions in the equipment located at the custom
    11·1 answer
  • What specific database stores local user accounts on local computers, and allows users to sign in to and access resources only o
    9·1 answer
  • Write a program that has the following String variables: firstName, middleName, and lastName. Initialize these with your first,
    7·1 answer
  • Char[][] array1 = new char[15][10];
    5·1 answer
  • He flow of electric charges through a material describes an electric _______.
    10·1 answer
  • Develop an algorithm to print the names of the candidates who should receive a refund. A refund is due if the candidate's votes
    7·1 answer
  • A market-product strategy that requires no change in the basic product but instead seeks new buyers is known as ______
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!