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]
2 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]2 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
Imagine you are building an ATM system; list at least 6 application domains for the system. That is, in which context is the sys
Anvisha [2.4K]

Answer:

Six applications domains for the ATM was listed below in the explanation section below

The main aim of the ATM is cash collection, user information update.

The users of the ATM are people, staff, customers/clients.

Explanation:

Solution

Given that

The Application domain for the system is given below:

  • The System is going to verify the details entered
  • Update the database on the server side
  • Calculation of cash Available
  • Count the Cash and Identify the note in the Machine
  • Troubleshooting of the ATM machine (system)
  • Backup of the system and Operating system /Software installed on the ATM machine.

The ATM is going to be used for the purpose of collecting cash, updating user information, cashing cheques etc and is used by all the Bank customers.

Who are the users of ATM:

  • Customers at the bank
  • Individuals /people
  • Staff of the Bank
3 0
3 years ago
The name of a .java file should ______________________________. Always match the name of the Class inside Should always start wi
natita [175]

Answer:

The name of a .java file should <u>always match the name of the class inside.</u>

Explanation:

In Java programming the program written in code editor is first saved with .java extension. The name of this .java file should be same as that of  the class declared inside the file.

This .java file is then compiled and  converted to .class file which contains the java bytecode. This bytecode can then be executed by java virtual machine(JVM).

However it is not always necessary that name of .java files should be same as that of class inside it. The name should be same only when the class inside is declared as public.

In case it is not declared as public one can name .java file different than the actual class name.  

7 0
2 years ago
Write a program to calculate the area of a triangle whose base is 10cm and height is 6cm
Tcecarenko [31]

Answer:

30cm

Explanation:

Height X Base

6cm X 10cm

60cm

Then take half because a triangle is half a square and we are using a square formula.

60cm divided by 2

=30cm

7 0
2 years ago
Help pls<br> cmu cs 0<br> 4.1.2.1 Creating Groups checkpoint 1
Sindrei [870]

Answer:

Explanation:

Circle(centerX, centerY, radius, fill='black', border=None,

borderWidth=2, opacity=100, rotateAngle=0, dashes=False,

align='center', visible=True)

8 0
2 years ago
Read 2 more answers
What shortcut keys do i use to print something on my keyboard ?
romanna [79]
CTRL+P. It's usually pressed when you want to print something.
5 0
2 years ago
Read 2 more answers
Other questions:
  • What is requirement analysis
    8·1 answer
  • What is Least effective at preventing a computer virus
    10·1 answer
  • Write an examples of Output device, storage devices and inputs device 10 each excluding the common ones​
    5·1 answer
  • If you sort by Last Name, Ascending, which of the following last names would come first in the list?
    12·1 answer
  • The 8-bit ____ field is used by source network hosts and forwarding routers to distinguished classes or priorities in ipv6 packe
    11·1 answer
  • Which cable would you check if you can't access any web pages?
    12·1 answer
  • Here is a list of storage devices:
    5·1 answer
  • When you create a new database using --------- , the database includes prebuilt tables and forms which you can populate with dat
    15·1 answer
  • Look at the code in the example below, and then answer the question.
    9·1 answer
  • I'm not sure how to solve this problem
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!