How to fix this error in a Pythagorean theorem

205 Views Asked by At

So i have easy program that will tell me if this Pythagorean theorem a2 + b2 = c2 is true or false.

But there is one problem if I try to activate it like 2 times without typing something program will fail Is there anything how to fix it.

a=int(input("enter a number a:"))    
b=int(input("enter a number b:"),)      
c=int(input("enter a number c:"),)

result= (((a**2)+(b**2)) == (c**2))     



print(f"result =  {result}")       

here is error ValueError:

 invalid literal for int() with base 10: 
1

There are 1 best solutions below

1
Code-Apprentice On

It sounds like you just pressed Enter without typing any numbers. If you do that then input() will return an empty string and int("") will cause the error. This is because int expects a valid numerical string passed to it.

To solve the problem, you need to disallow empty input. You can add error handling with a while loop to check the entered value and ask the user to enter a correct value.