Write a function that takes a string consisting of alphabetic
characters as input argument and returns True if the string is a
palindrome. A palindrome is a string which is the same backward or
forward. Note that capitalization does not matter here i.e. a lower
case character can be considered the same as an upper case character.
这是我的代码:def Palindrome_test_string (input_str):
output_str = ""
count = 0
for k in range (len(input_str) - 1, -1, -1):
output_str = output_str + input_str[k]
print ("The reverse of the string is:",output_str)
for i in range (0, len(input_str)):
if (output_str[i] == input_str[i]):
count += 1
else:
break
if (count == len(input_str)):
return (True)
else:
return (False)
#Main Program
test_str = "Radar"
result = Palindrome_test_string (test_str)
print (result)
它显示了大多数情况下的正确输出,但是这个程序有一个问题。当我输入'Radar'时,它的反面应该是'Radar',根据这个问题,我必须在比较时考虑大小写字符相等。如何做到这一点?任何帮助都将不胜感激。在