Ask coding questions

← Back to all posts
Printing Integrers
IzanLarumbe (29)

How can i print integers??

Answered by ash15khng (472) [earned 5 cycles]
View Answer
Commentshotnewtop
ash15khng (472)

The reason why the code isn't working is because you're trying to add a string and an integer, which just doesn't work. You have to convert the integer into a string by using str() then you can use the + symbol to concatenate them.
For example:

# Next line will give an error
print("Hello" + 123)
# To fix this, convert the integer to a string:
print("Hello" + str(123))

Also side note, you should post your repl link instead of just a screenshot.

IzanLarumbe (29)

Also in the line that says

Votantes = Votantes+20

is now:

Votantes = +20
mwilki7 (511)

@IzanLarumbe
You want Votantes to have the positive number 20?

IzanLarumbe (29)

@mwilki7 No, i want it to add 20 to the actual value, for example if you have 0 then i want the variable to have 20 so i do +20

and then if you have 20 and you get 20 more so you can have 40

Also i need to know how to print them. Cause it says it has to be a string.

mwilki7 (511)

@IzanLarumbe I'm not sure why adding to the variable is giving you an error but you can concatenate stuff together .. for printing:

print("Votantes:" .. Votantes)
mwilki7 (511)

@theangryepicbanana Oh I thought this was lua
should have looked at the pictures lol

IzanLarumbe (29)

@mwilki7 Ya i also code in lua, i dont have problems in it. Is ez