Python Forum
ZeroDivisionError help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ZeroDivisionError help
#1
I have spent way to much time on this. What I need to do, make a math tutor. I have this entire thing figured out but this.

What it needs to do, if a zero is input, I need it to read an error and then loop ONLY to the division...not back to the main menu.

Please tell me there is someone who can help. I have tried so many things for the last three days and my eyes are going cross.

#division calculation
        elif choice == divF:
            try:
                num1 = int(input("Enter first number: "))
                num2 = int(input("Enter second number: "))

                c_answer = (num1 / num2)

            except ZeroDivisionError:
                print("Cannot use a zero in division, please try again")

            answer = float(input("Enter answer:"))

#output
            if c_answer == answer:
                print("Correct, great job!")
            else:
                print(f'Incorrect, the answer is {c_answer:.2f} .')
 

This currently will ask for first and second number, then show the error....but then asks for answer (which is obviously going to work)...then it shows the error. If a zero is input in the first two numbers, then an error needs to show, then loop back to ask for the numbers again until no zeros are input. Then it continues with the program.

**be kind, this is my first post in any group...and this is my first programing class ever.**
Reply


Messages In This Thread
ZeroDivisionError help - by zimmytheflygirl - Jun-18-2024, 05:57 PM
RE: ZeroDivisionError help - by Jeff_900 - Jun-18-2024, 07:17 PM
RE: ZeroDivisionError help - by zimmytheflygirl - Jun-18-2024, 07:22 PM
RE: ZeroDivisionError help - by Jeff_900 - Jun-18-2024, 07:30 PM
RE: ZeroDivisionError help - by zimmytheflygirl - Jun-18-2024, 07:45 PM
RE: ZeroDivisionError help - by zimmytheflygirl - Jun-18-2024, 07:56 PM
RE: ZeroDivisionError help - by Jeff_900 - Jun-18-2024, 08:00 PM
RE: ZeroDivisionError help - by deanhystad - Jun-19-2024, 12:43 AM
RE: ZeroDivisionError help - by Pedroski55 - Jun-21-2024, 03:14 PM
RE: ZeroDivisionError help - by zimmytheflygirl - Jun-21-2024, 11:58 PM
RE: ZeroDivisionError help - by deanhystad - Jun-22-2024, 03:22 AM
RE: ZeroDivisionError help - by zimmytheflygirl - Jun-24-2024, 01:15 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020