Question

Write a python program that does the following: Prompts the user for three numbers in one...

Write a python program that does the following:

Prompts the user for three numbers in one request.
Be sure to specify the “delimiter” by which a user enters those three numbers.

Divides the first number by the second number and add that result to the third number.

Prints output that shows in one line the formula applied and the result of the calculation.
Validate input by:

•    Checking the user entered 3 values

•    Appropriately checking for the following errors: ValueError and ZeroDivisionError.

•    Printing descriptive error messages to the console if validation fails.

  • Remembering to have very granular testing blocks

No Example Output provided for this question.

Homework Answers

Answer #1

The code given below takes the inputs and outputs the result for valid input.Its displays appropriate errors for zero division and improper inputs

values=input("Enter three space separated numbers: ").split() 

if len(values)!=3:
  print(f"ValueError! {len(values)} numbers found, Please enter three numbers")
else:
  a=int(values[0])
  b=int(values[1])
  c=int(values[2])

  while (b<= 0): #keep on taking input for second number until its equal to 0
    b = int(input("ZeroDivisionError! Please enter a valid denominator: "))

  result = a/b + c
  print("The result of the formula a/b + c = ",result)

-----------------------------------------------------------------------------------------

Do upvote if you liked the solution. happy learning!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT