Question

USING PYTHON *Write a program, in which the user enters two numbers, then divides the first...

USING PYTHON

*Write a program, in which the user enters two numbers, then divides the first number by the second, and prints the result to two decimal places.

*Make sure that that the inputs are floats (with exception handling using the ValueError).

*Make sure that there is no divide by zero error (with exception handling).

*Then have a plain exception: That handles any other error.

-Thank you in advance for your assistance-

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, please go threw the code and ouput.

import sys
def main():
i = float(raw_input("Enter 1st number: ")) #ask user to enter data
j = float(raw_input("Enter 2nd number: "))
try:
result = float(i/j)
except ZeroDivisionError: #handle divide by zero error
print("You can't divide by zero")
else:
print(result)

if __name__ == "__main__":
main()

Add a comment
Know the answer?
Add Answer to:
USING PYTHON *Write a program, in which the user enters two numbers, then divides the first...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • Write a program which: - prompts the user for 2 numerical inputs - stores their two...

    Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...

  • Python Write a function called division that takes as input 2 numbers and divides them without...

    Python Write a function called division that takes as input 2 numbers and divides them without first checking what the inputs contain, returning the value of the division if it succeeds. If one of the inputs is not a number, print 'Cannot divide anything but numbers'. If denominator is 0, print 'Attempted to divide by zero'. If anything else causes the division to not work, print 'An unknown error occurred'. >>> division (6,2) >>> division(3, a) 'Cannot divide anything but...

  • write a java program that prompts a user to enter two different numbers, divide the first...

    write a java program that prompts a user to enter two different numbers, divide the first number by second and prints the result

  • Using PYTHON create a program to allow the user to enter a phrase or read a...

    Using PYTHON create a program to allow the user to enter a phrase or read a file. Make your program menu-driven to allow the user to select a option to count the total words in the phrase or file. In addition, provide a menu-selection to count the number of words start with a vowel and a selection to count the number of words that start with a consonant. Include exception handlers for file not found, divide by zero, and index...

  • In Python Calculator Write a program that allows the user to enter two numbers and then...

    In Python Calculator Write a program that allows the user to enter two numbers and then adds, subtracts, divides or multiplies them when the user clicks on the appropriate button. Make sure you have a Quit button. Modification and requirements”: _____Window title should be  your name Calculate self.main_window.title("?????") _____Labels - change the attributes of the color, font, size and bold the answerExample self.label = tkinter.Label(self.main_window, \ text='?????????!', font=(" should Arial", 12, "bold"), fg="blue", bg="pink")Tip: choose a color from the...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • Write a program that accepts numbers entered by the user until the user enters a zero....

    Write a program that accepts numbers entered by the user until the user enters a zero. The program then must display the largest value that is smaller than zero. This should be java program

  • Write an assembler program that asks the user (as shown below) for two integers and a...

    Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...

  • please solve using python thank you! Write a program which prompts the user to enter a...

    please solve using python thank you! Write a program which prompts the user to enter a number of rows, and prints a hollow square star pattern with 2 diagonals. Note: you can assume that the integer will always be > 1 and will be an odd number. For example: Input Result 5 Enter number of rows: 5 ***** ** ** * * * ** ** ***** 9 Enter number of rows: 9 ** ** ** * * * * *...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT