Ask coding questions

← Back to all posts
1
Printing Integrers
IzanLarumbe (27)

How can i print integers??

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

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.

1
IzanLarumbe (27)

Also in the line that says

Votantes = Votantes+20

is now:

Votantes = +20
1
mwilki7 (111)

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

1
IzanLarumbe (27)

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

1
mwilki7 (111)

@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)
1
1
mwilki7 (111)

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

1
IzanLarumbe (27)

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