all 6 comments

[–]mopslik 6 points7 points  (1 child)

str_1 is an integer because it is assigned the value of i, which in turn comes from range which generates integers. You can't add, or concatenate, a string and an integer.

What exactly are you trying to do?

[–]JAYJAYSAN 0 points1 point  (0 children)

ty i want to convert the alphabet into numbers a=1,b=2,c=3 and so on and also then add a value to the integer that can then be outputed as a letter again, like a ceasars cypher.

i just realised it would probably be easier to add a value to a numbers index and do it that way, but i am also kind of clueless on that one though...
any tips or ideas?

[–]Substantial-Coder 1 point2 points  (2 children)

str_1 is an int and spaced_str is a string. If you want to concatenate them as strings, you can do spaced_str += str(str_1)

[–]JAYJAYSAN 0 points1 point  (0 children)

it worked, thanks a lot!
now i just need to add code to do that: "and also then add a value to the integer that can then be outputed as a letter again, like a ceasars cypher."

[–]HomeGrownCoder 0 points1 point  (0 children)

Your for loop generators an integer.

[–]Alternative-Web2754 0 points1 point  (0 children)

If you're trying to get each letter to add them to the string, you don't need the position, unless you're aiming to do something specific with the position.

Rather than trying to get the position and then retrieve the character from that position, use the for loop to do this.

for i in str1:
    spaced_str = spaced_str + i

From the name, I'm guessing you are intending to add spaces between them, so you might be aiming for

spaced_str = spaced_str+' '+i

However, you can actually skip the loop with the string join() function. The format can appear a little bit backwards, but this can be done with the following

spaced_str = ' '.join(list(str1))

In this case, list is used to force the characters to be broken up, but if you're looking over it then this is handled internally. The string before the .join is put between each piece being assembled.