Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading