0

(Python) name “s” is not defined

It’s about the reverse practice. I wanna know what’s wrong with my code... Given a list lst = ["apple","ztc","python"] ##Output: ['elppa', 'ctz', 'nohtyp'] def reverse_string(s): hi=[] for i in range(len(lst)): s=str(lst[i]) hi.append(s[::-1]) return hi print(reverse_string(s))

3rd Apr 2018, 7:26 PM
Vicky Kuo
Vicky Kuo - avatar
4 Respostas
+ 1
The s in the print(... (s) ) Is not defined. Replace it with the string you want to reverse or initialize and define it by writing s='something' before you call the last statement
3rd Apr 2018, 7:30 PM
Chrizzhigh
Chrizzhigh - avatar
+ 1
it’s a very obvious mistake...😛😛😛thanks for your patience â˜ș
3rd Apr 2018, 8:55 PM
Vicky Kuo
Vicky Kuo - avatar
0
print (reverse_string("hello")) to test it. Note, the variable s isn't defined outside the function reverse_string(). You need to research the concept called 'variable scope'.
3rd Apr 2018, 7:31 PM
Emma
0
We all make obvious mistakes, hence why coding reviews are so helpful â˜ș Team work essential to better code.
3rd Apr 2018, 10:25 PM
Emma