a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
sum1 = float(input(f"Enter {a} * {b}= "))
sum2 = a*b
if sum1 == sum2:
print("Correct")
else:
print("Incorrect")
其余都没毛病,唯独计算0.1✘3.0=0.3一直输出incorrect
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
sum1 = float(input(f"Enter {a} * {b}= "))
sum2 = a*b
if sum1 == sum2:
print("Correct")
else:
print("Incorrect")
都用round保留下小数位再比较就好了
a = round(float(input("Enter the first number: ")))
b = round(float(input("Enter the second number: ")))
sum1 = round(float(input(f"Enter {a} * {b}= ")))
sum2 = a*b
if sum1 == sum2:
print("Correct")
else:
print("Incorrect")