Python - Creating a Reversed String Using a For Loop -


i'm trying figure out how create reversed string using loop. it's understanding isn't efficient way of doing assignment's parameters specify have use loop. have seems should work keep getting error: "typeerror: 'str' object not callable" "line 7, in reversestring test2 = test1(n)".

def reversestring(test1):     global test2     test2 = ""     n in range (len(test1)-1, -1, -1):         test2 = test1(n)         print (test2)         return test2  #input  test1 = input("enter string test if palindrome: ")  reversestring(test1) 

you're trying call string see in error message test1(n) want index string doing test1[n].

also, return inside loop want outside, , want use += concatenate instead of reassigning on every iteration.

i'm assuming exercise , thats why you're doing iteratively. nonetheless, sake of completeness reverse string can test1[::-1]


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -