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
A communications medium that carries a large amount of data at a fast speed is called
babymother [125]
Either Firewire, or an ethernet cable.
7 0
3 years ago
The variable used in a loop to control the number of times it is executed is called a _______.
tia_tia [17]

Answer:

the variable used in a loop to control the number of timer is executed is called a interaction.

Explanation:

a particular way in which matter, fields, and atomic and subatomic particles affect one another

6 0
3 years ago
What is the synonym for term port?
Rus_ich [418]
The synonym for term port is seaport

3 0
3 years ago
Djdjdjdjdjdjdjdjdjjdjdjdjdjdjdjdjdjdjdj
DanielleElmas [232]
Shorty a bad bleep .
7 0
2 years ago
Read 2 more answers
What is the difference between 1080p and 2k?
professor190 [17]
They have the same  vertical resolution. I can suggest you to watch the video in youtube .<span>https://www.youtube.com/watch?v=uluEEGBHyUE</span>
7 0
2 years ago
Other questions:
  • 1. _______ is when two things happen at one time when using the Scratch program.
    6·1 answer
  • Which of the following describes a BYOD?
    15·1 answer
  • How to write a self-analysis essay
    5·1 answer
  • Which course must first-time drivers in Florida take to be eligible for their Learner License?
    11·1 answer
  • Josh wants to convey his best wishes to johnathin for a meeting schedualed later diring the day. Which business documented would
    7·1 answer
  • You may nest while and do-while loops, but you may not nest for loops<br><br><br><br> True False
    10·1 answer
  • What do you mean by GIGO (Garbage-In-Garbage-Out) in computer system?​
    6·1 answer
  • Hat is the purpose of the domain name?
    7·2 answers
  • In dynamic programming, the technique of storing the previously calculated values is called A. Saving value property B. Storing
    7·1 answer
  • What free website can you record videos on, and edit them without money?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!