You have to initialize str2
:
str2 = ''
while c<b:
str2 += str1[c]
c+=1
print str2
Or else do a function that receives str2
as parameter:
def myfunc(str2=''):
while c<b:
str2 += str1[c]
c+=1
return str2
where str2
parameter is by default initialized as ''
, i.e. empty string.
1
solved Python: Why dosent this work? [closed]