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))
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
+ 1
itâs a very obvious mistake...đđđthanks for your patience âșïž
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'.
0
We all make obvious mistakes, hence why coding reviews are so helpful âș Team work essential to better code.