So I just started to learn how to code. I want to write a piece of code that detects which of the try inputs was entered incorrectly, and return them to that line of code.
from fractions import Fraction
import math
def Calc() :
try :
Length1 = abs(float(Fraction(input("First Rectangle Length:\n"))))
Width1 = abs(float(Fraction(input("First Rectangle Width:\n"))))
Length2 = abs(float(Fraction(input("Second Rectangle Length:\n"))))
Width2 = abs(float(Fraction(input("Second Rectangle Width:\n"))))
except :
print ("please enter numeric values")
RECTANGLE2 = Length2 * Width2
RECTANGLE1 = Length1 * Width1
if RECTANGLE1 > RECTANGLE2 :
print (f"The First Rectangle Is Bigger! It's Area Is:\n{RECTANGLE1}")
elif RECTANGLE1 == RECTANGLE2 :
print (f"The Rectangles Are The Same! Their Area Is:\n{RECTANGLE1}")
else :
print (f"The Second Rectangle Is Bigger! It's Area Is:\n{RECTANGLE2}")
The code is designed to ask the user for the area of 2 rectangles and determine which one is bigger. If someone were to input a str on Length2, I want to return them to ONLY length2. I don't want my code to re-ask them Length1 and Width1.