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
5 of 10
DaniilM [7]

Answer:

what

Explanation:

3 0
2 years ago
Microsoft word is an example of utility software? <br><br>A.true <br>B.false​
monitta

Answer:

false

Explanation:

Ms word is only an application software

7 0
2 years ago
Read 2 more answers
What is a good monitor for console gaming? (Any price)
likoan [24]

Answer:

I personally use a alienware

Explanation:

7 0
3 years ago
Read 2 more answers
Discuss the major differences in two approaches ofprogramming i.e. Object oriented programming and structuredprogramming.
Romashka-Z-Leto [24]

Answer:

Differences between Object Oriented Programming and Structured Programming

1. Structured programming focuses on process/logic then data while OOP(Object Oriented programming) focuses on data.

2.OOP supports Inheritance,Encapsulation,Abstraction,Polymorphism while structured programming does not supports these.

3.Structured programming follows top-down approach while OOP follows bottom-up approach.

4.OOP is more secured than structured programming because it supports Abstraction (data hiding).

7 0
3 years ago
Consider the university enrollment database schema: 547 Student(snurn: integer, snarne: string, majoT: string, level: string, ag
trapecia [35]

Enroll a student identified by her snum into the class named 'Introduction to Database Systems' is the following transactions, state the SQL isolation level you would use.

1. Enroll a student identified by her snum into the class named 'Introduction to Database Systems'.

<u>Explanation:</u>

Since enroll is unique in the university enrollment database schema and field name is SNUM and it is data type is an integer. To identify student class name and department name and name of student SNUM field is used for searching in university enrollment database schema. Enrollment changing is not possible of the student’s not possible or not good practices in university enrollment database schema.

If a query had been made class wise or department wise enrollment is played an important role.

For  assign, a faculty is made on the class id or  department id.

8 0
3 years ago
Other questions:
  • The keyboard, mouse, trackpad, microphone, light pen, and voice recognition are examples of _____ devices.
    5·1 answer
  • How do i start makeing a Character in the Unreal Game Engine
    14·2 answers
  • Which of the following describes ETL? a) A process that transforms information using a common set of enterprise definitions b) A
    14·1 answer
  • Is USA TestPrep a test-taking site that won't let you access other windows without kicking you off?
    13·1 answer
  • What is the most difficult part of working with the Help system?
    8·1 answer
  • I need help with writing the code in Python that draws an arrow pointing to the right.
    15·1 answer
  • What does digital mean, in the term of computer science.
    11·1 answer
  • B. Some of Company X's new practices and systems are unethical. Business ethics is a set of codes
    5·1 answer
  • Why media is far from government​
    6·2 answers
  • What kind of AR target category makes sense for a playing card with a picture on it?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!