Creating a faulty calculator that returns all the values correctly except 3 values that are given in an exam
while True:
try:
num1 = int(input("number 1: "))
num2 = int(input("number 2: "))
operator = input("Operator: ")
if operator == "+":
a = num1 + num2
if (num1 == 56 and num2 == 9) or (num1 == 9 and num2 == 56):
print("77")
else: print(f"The sum of your numbers is {a}")
elif operator == "-":
b = num1 - num2
print(f"Subtracting Number-2 from Number-1, the result is {b}")
elif operator == "/":
c = num1 / num2
if (num1 == 56 and num2 == 6):
print("4")
else: print(f"The division result is {c}")
elif operator == "*":
d = num1 * num2
if (num1 == 45 and num2 == 3) or (num1 == 3 and num2 == 45):
print("555")
else: print(f"Multiplying the two numbers, the result is {d}")
elif operator == "%":
e = num1 % num2
print(f"The remainder is {e}")
else:
print("Enter all the required inputs please!")
except:
print("Enter the required inputs, then press ENTER")
Comments
Post a Comment
Write something to CodeWithAbdur!