如何编写Python代码实现预期输出 解决代码运行无显示问题
问题原因
Python 强制要求用缩进标识代码块的归属,你提供的代码中两个for循环下属的print语句没有做缩进,不属于循环的执行范围,运行时要么直接触发缩进错误,要么逻辑不执行导致没有对应输出。
修正后可运行代码
word = 'Python' print("The original string is = ",end = '') for ch in word : # ch will take each character from name print(ch , end = ' ') print("\n") length = len(word) # len is function to give no. of characters print("The reversed string is = ",end = '') for ch in range(-1, (-length - 1), -1) : print(word[ch], end = ' ')
运行输出结果
The original string is = P y t h o n The reversed string is = n o h t y P
内容的提问来源于stack exchange,提问作者Kushagra Lal
相关产品推荐
相关产品推荐

