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 odpowiedzi
+ 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.