问题
所以,我的问题是我在这一行TypeError: string indices must be integers
获得userCHR += str(user[i])
,但代码看起来很好。有人能帮助我吗?
Python代码
user = input("Please enter a string: ")
user = user.upper()
userCHR = ""
for i in user:
userCHR += str(user[i])
print(userCHR)
答案 0 :(得分:-1)
如果我没错,那我就是一个字符串。 也许你可以试试:
for i in user:
userCHR += i
答案 1 :(得分:-1)
for循环在Python中返回字符串中的字符,而不是整数位置。
userCHR += str(user[i])
userCHR += i
user = input("Please enter a string: ")
user = user.upper()
userCHR = ""
for i in user:
userCHR += i
print(userCHR)