Jun-22-2024, 12:06 AM
Ok..I am making a math tutor program...student chooses a process (add, sub, div, mul), then enters first number, second number, and then answer.
This works for division...except when the answer is a number such as 3.3333333 or .333333. If I input 3.33 or .33 the program says the answer is incorrect and then shows the correct answer at 3.33 or .33. The program is supposed to show round to two decimal points.
My question, how to I make it so the program excepts the rounded number? (note... all the elements that you see are needed...enter first number, enter second number, enter answer, correct or incorrect response with the correct answer) I finally figured out how to make it loop back to the question if a zero is entered)
This works for division...except when the answer is a number such as 3.3333333 or .333333. If I input 3.33 or .33 the program says the answer is incorrect and then shows the correct answer at 3.33 or .33. The program is supposed to show round to two decimal points.
My question, how to I make it so the program excepts the rounded number? (note... all the elements that you see are needed...enter first number, enter second number, enter answer, correct or incorrect response with the correct answer) I finally figured out how to make it loop back to the question if a zero is entered)
#division calculation elif choice == divF: while (num1 := int(input('Enter first number: '))) == 0: print ('Number must not be a zero.') while (num2 := int(input("Enter second number: "))) == 0: print ('Number must not be a zero.') answer = float(input("Enter answer (to 2 decimal points): ")) c_answer = float(num1 / num2) #output if c_answer == answer: print("Correct, great job!") else: print("Incorrect, the answer is ", f'{c_answer:.2f}',".")