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
What is meant by the term text?
krek1111 [17]

Answer:

It's D

Explanation:

5 0
3 years ago
Read 2 more answers
What does a transistor do?
mixas84 [53]

It Transmits electrical currents. You can use it as an amplifier or switch of currents.

5 0
3 years ago
Read 2 more answers
How do you hack a iPhone, Like If you forgot your password and want to get back in your phone. What do you do?
s344n2d4d5 [400]

Answer:

fix it on itunes

Explanation:

or get a new one

6 0
3 years ago
Read 2 more answers
When you see an ad on social media that relates to your profile or something
sesenic [268]

Answer:

Tritium BF

Explanation:

5 0
2 years ago
Read 2 more answers
3.5 Code Practice: Question 1<br> (Website: Edhesive)
igor_vitrenko [27]
Sorry the website wasn’t working for me
3 0
2 years ago
Other questions:
  • Why was the movable type of the printing press such a breakthrough for publishing?
    15·2 answers
  • On your Windows server, you’re planning to install a new database application that uses an enormous amount of disk space. You ne
    11·1 answer
  • A user prefers an external monitor, mouse, and keyboard for a laptop. The user does not want to use the built-in screen; however
    5·1 answer
  • "What is the database in which Windows stores all information about hardware, applications, users and system settings?"
    8·1 answer
  • Nathan wants to create multiple worksheet containing common formatting styles for his team members. Which file extension helps h
    9·1 answer
  • Write a statement that increases the value of the int variable total by the value of the int variable amount. that is, add the v
    5·1 answer
  • Help me find the difference between these logos
    10·2 answers
  • Before posting a picture online, make sure to
    7·1 answer
  • You are splitting up all your apples equally between 3 people. which statement below will calculate how many apples will be left
    12·1 answer
  • Unlike radio frequency identification (RFID) tags, bar codes: Question 30 options: require a reader that tunes into a specific f
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!