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
lesantik [10]
2 years ago
12

Write a Python 3 program that prompts the user for 3 postive numbers (or zero) and then adds them together. If the user enters a

negative number, the program should reprompt them until they enter a postive number. Divide your program into two functions: prompt_number - Prompts for a number, and keeps re-prompting as long as it is negative. Then, returns the number. compute_sum - Accepts 3 numbers, adds them together and returns the sum. main - Calls the prompt_number function 3 times, saves the return value into three different variables, then passes those 3 variables to the compute_sum function. Finally, saves the result of compute_sum into a variable and displays it.
Computers and Technology
1 answer:
Citrus2011 [14]2 years ago
6 0

Answer:

def prompt_number():

   while True:

       number = int(input("Enter a number: "))

       if number >= 0:

           break

       

   return number

   

def compute_sum(n1, n2, n3):

   total = n1 + n2 + n3

   return total

   

n1 = prompt_number()

n2 = prompt_number()

n3 = prompt_number()

result = compute_sum(n1, n2, n3)

print(result)

Explanation:

Create a function named prompt_number that asks the user to enter a number until a positive number or 0 is entered and returns the number

Create a function named compute_sum that takes three numbers, sums them and returns the sum

Ask the user to enter three numbers, call the prompt_number() three times and assign the values

Calculate the the sum, call the compute_sum and pass the numbers as parameters

Print the result

You might be interested in
Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/kmâ
zvonat [6]

Answer:

class Car(object):

   fuel = 0

   def __init__(self, mpg):

       self.mpg = mpg

   def drive(self, mile):

       if self.fuel * self.mpg >= mile:

           self.fuel -= mile / self.mpg

       else:

           print(f"get gas for your {self}")

       print(f"Fuel remaining: {self.fuel}")

   #classmethod

   def get_gas(cls):

       cls.fuel += 50

   #classmethod

   def add_gas(cls, gallon):

       if cls.fuel + gallon > 50:

           cls.fuel += 10

       else:

           cls.fuel += gallon

gulf = Car(20)

gulf.get_gas()

gulf.drive(200)

Explanation:

The Car class is defined in Python. Its drive method simulates the driving of a car with fuel that reduces by the miles covered, with efficiency in miles per gallon. The get_gas and add_gas methods fill and top up the car tank respectively.

3 0
2 years ago
2. "The only requirement for a person to use a computer is that you should be able to read and
Lena [83]

Answer:

False.

Explanation:

Most computers have options that allow you to change the language if needed.

6 0
2 years ago
Type size in a textbook may be used to indicate the relative importance of ideas.
Alborosie
Yes true 

hey is this one of your questions on a science packet if so it is called explore ring Earth's surface because I have the same packet with the same question on it
3 0
2 years ago
Read 2 more answers
An asymmetric encryption system utilizes how many keys?
ivanzaharov [21]
Two. One for encryption, and one for decryption. RSA is an example of an asymmetric encryption algorithm.
7 0
3 years ago
What is the function of ROM?
Gnoma [55]

Answer:

Hello, There!

<h2>Your Question↓</h2>

What is the function of ROM?

<h2>Answer↓</h2>

Allows parts of the computer to communicate is the Correct Answer.

Explanation:

<h2>Now you May Ask What does it do or How it works↓</h2>
  • ⇒ROM provides the necessary instructions for communication between various hardware components.
  • ⇒ it is essential for the storage and operation of the BIOS, but it can also be used for basic data management, to hold software for basic processes of utilities.

Tip: Wanna know how to earn points back for asking your Question?

If you do it's easy just when two people answer your question whichever answer you think is the best click the crown on the side to get 25% of your points back! :D

Therefore, I hope this helps!

6 0
2 years ago
Other questions:
  • To create a chart you need to select at least ___ in a range of data
    15·1 answer
  • Holly would like to run an annual major disaster recovery test that is as thorough and realistic as possible. She also wants to
    5·1 answer
  • (BRAINLIEST QUESTION!!!)
    11·1 answer
  • Consider the following code:
    6·1 answer
  • _____________are where you get down to business and enter data in a worksheet
    12·1 answer
  • What’s cloud-based LinkedIn automation?
    14·1 answer
  • Help me with the question please..​
    6·1 answer
  • LIST THE BEST 10 3D PRINTERS WITH THEIR RESPECTIVE APPLICATION SOFTWARES.
    5·2 answers
  • Select the correct text in the passage.
    12·1 answer
  • Describe the information technology industry today
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!