Nov-15-2020, 06:37 AM
Looking at your code I think you misunderstand how the try/except works. When there is error in the
Probably you want to have
For completeness you should know there can be also
try
block it looks at the exceptions. You handle ValueError and you also have all-catching blank
except`. When you enter a negative number, no exception is raised so no except block is entered.Probably you want to have
else
part. It will run after the try
block if no
except` block was enteredtry: len1 = (float(input("Enter the length of one side of the triangle: "))) len2 = float(input("Enter the length of a different side: ")) len3 = float(input("Enter the length of the final side: ")) except ValueError: print("Please enter a number.") else: if len1 <= 0 or len2 <= 0 or len3 <= 0: print("Please enter a positive number.")Note that it will print the message and just continue with program execution.
For completeness you should know there can be also
finally
- i.e. this code will be executed always, regardless of except
part being executed or not.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs