我需要帮助,我的编码有问题,似乎无法弄清楚是什么..我确定这是一个简单的错误,只是我目前似乎无法找到它
string = raw_input("Enter String->")
length = len(string)
index = 0
while index < length:
if string(index) == 'a':
print "Character found is a"
index = length
elif string(index) != 'a':
print "Character", index"is not an a, sorry"
错误当然是“无效的语法”
这是迄今为止的新代码
string = raw_input("Enter String->")
length = len(string)
index = 0
while index < length:
if string[index] == 'a':
print "Character found is a"
index = length
elif string[index] != 'a':
print "Character", index,"is not an a, sorry"
从这里开始,当我运行代码时,它会无限运行“字符 0 不是 a”
第三次编辑
string = raw_input("Enter String->")
length = len(string)
index = 0
while index < length:
if string[index] == 'a':
index += 1
print "Character found is a"
break
elif string[index] != 'a':
print "Character", index, "is not an a, sorry"