# I need some help

I am learning to code and am trying to code a basic math game. I have set it up to pick sums from a set of numbers at random, but i am unsure on how to be able to detect when it is right or wrong.
Also i would attach my repl here but i dont know how, if it is needed it would be greatly appreciated if you could tell me how.
Thanks

Hey, @EoinLarkin1 !

Can you please provide a link to the repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

Do note that you’ll need to change the appropriate fields to your username and name of your repl.

that should work, tysm

Hi @EoinLarkin1 !
I found an error here:

``````times = "multiplied by"
print(sum, times, sum2)
if input() == "sum" + "sum2":
print("That is correct!")
else:
print("That is wrong.")
``````

As it should be `if answer== "sum" + "sum2":`, the code should be amended to this:

``````times = "multiplied by"
print(sum, times, sum2)
if answer == "sum" + "sum2": # Not the input that is checked, as this will cause 2 inputs to be asked.
print("That is correct!")
else:
print("That is wrong.")
``````

Additionally, it should be `*` instead of `+` in the `if` statement.
Correct code:

``````times = "multiplied by"
print(sum, times, sum2)
if answer == sum * sum2: # The quotes "" was removed around sum as you are checking against a number, not a string.
print("That is correct!")
else:
print("That is wrong.")
``````

Now, at the last bit, it will say `_ is correct!` ( `_` is your answer), no matter if it is correct or wrong.Here’s how you fix it:

``````print("this is the final level. Try your best!")
options = (1, 2, 3, 4, 5, 6, 7, 8, 9)
sum = random.choice(options)
sum2 = random.choice(options)
over = "divided by"
print(sum, over, sum2)
if answer == sum / sum2: # This is the division symbol. You can also use //
else:
print("You answer is worng!") # Displays a faliure message
``````

With these fixes, your code should work accurately.
Hope this helps! If it solves your problem, you can mark this post as a Solution.
DISCLAIMER: I did NOT use an AI tool to write this, though the language used might’ve sounded like it.

2 Likes

Hi @EoinLarkin1 !
Have you tried what I suggested? Does it work?

@EoinLarkin1 BTW The reason this
`if answer == "sum" + "sum2":`
Is changed to this:
`if answer == sum * sum2:`
Is because before you had them as strings (contained `”`) your answer would have had to be `"sumsum2"` because of the `+` is was concatenating the two strings together. The `*` also makes it a multiplication problem rather than an addition problem, since an asterisk (`*`) stands for the multiplication sign in programming (it is like the `•` multiplication sign, its just the way your code knows).

1 Like

I am currently quite busy but i will implement these changes and get back to you as soon as i can. Thank you very much for your help, Hope you have a nice day

1 Like

The info has improved, however not everything is running accurately. Whether this is just me inputting it wrong i dont know.

This /nix/store/ commands with loads of random numbers after it keeps showing up and i cant remove it.

Also the code only detects that something is wrong.

This is very likely my fault and i apologize for that reason if it is the case, I would greatly appreciate it if you or someone else could review it again and try to help me. Thank you very much

Add this to the top of your `.replit` file:

``````run = "clear&&python main.py"
``````
2 Likes

thank you very much, the code does not appear. Would you also happen to be able to help me out with my code? I a m trying to code a basic maths game but my code only detects wrong answers.

https://replit.com/@EoinLarkin1/BoringOlivedrabFormulas

Remember that the `input()` function returns a string, not an integer. You should convert the input into an integer before comparing.

``````answer = int(input())
``````

Bad input may create an error though, which you might want to fix.
Also, for the final level, you may want to specifically generate numbers that don’t have a remainder when divided.

1 Like