Why can't I add numbers to a variable in Python?

So I am making a discord bot with discord.py that mutes someone if they’ve broken a certain amount of rules, and for this I need to add digits/numbers/integers to a variable. Here’s what I’ve tried so far:

x += 1;
x + 1;
x =+ 1;
x+1;
(x += 1);
(x) += 1;
(x) += (1);
(x + 1);
(x+1);

I need to be able to add the same integer multiple times to get the desired result, but none of the examples above seem to work. Is there one method I’ve missed?

>Solution :

It’s impossible to give a certain answer without knowing what you mean by "not seeming to work". Is an error being thrown?

My guess based on the limited information provided is that you are trying to modify x before defining it. Before modifying x, you must give it a value.

x = 0

Then you can modify it with either x = x + 1 or x += 1.

I’d recommend watching a video on python basics before trying to create something. It will be worth it in the long run.

Leave a Reply