Skip to content
Advertisement

Why do the math problems in my program repeat the same equation? [closed]

So, I’m trying to make a math problem in Python, since I’m a beginner learning how to code. Basically, it asks you how many questions you want to answer, and to answer questions of addition, subtraction, multiplication, and division correctly.

Let me show you the code I have, so far.

JavaScript

However, the drawback is that the same question repeats everytime (I am using my old laptop, so the p button and the quotation button is broken). Now my question is how to make the questions not repeat themselves.

Advertisement

Answer

There are a couple problems.

  1. You are testing for equality with “==” inside the “if” statements, when you probably would like to assign the true answer to a variable to compare to the user’s guess
  2. You are comparing the answer to the question, which is a string, which will never be equal

Fix the first one by creating a new variable for the true answer to keep it separate from the guess. Fix the second by comparing the guess to the real answer.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement