在 python 中打印两个条件输出
printing both the conditional outputs in python
下面是一个小程序,如果这个词是一个简单的词,正向流工作正常并给出正确的输出,但如果这个词不是一个回文,它会打印两个打印 statements.any 帮助赞赏..
x=input("Enter the word or sentance :")
a=len(x)
if a==1:
print("it is a one letter palindrome")
elif a>1:
y=0
while y<(a/2):
if x[y]==x[-(y+1)]:
print(x[y])
else:
print("it is not palindrome")
break
y=y+1
print("it is a palindrome")
您在最后一次打印调用之前缺少 space,因此它是在 while 循环终止后调用的。
更新:
Python 对间距敏感,我看不出您的评论中是否已修复此问题。试试这个:
x=input("Enter the word or sentance :")
a=len(x)
if a==1:
print("it is a one letter palindrome")
elif a>1:
y=0
while y<(a/2):
if x[y]==x[-(y+1)]:
print(x[y])
else:
print("it is not palindrome")
break
y=y+1
print("it is a palindrome")
下面是一个小程序,如果这个词是一个简单的词,正向流工作正常并给出正确的输出,但如果这个词不是一个回文,它会打印两个打印 statements.any 帮助赞赏..
x=input("Enter the word or sentance :")
a=len(x)
if a==1:
print("it is a one letter palindrome")
elif a>1:
y=0
while y<(a/2):
if x[y]==x[-(y+1)]:
print(x[y])
else:
print("it is not palindrome")
break
y=y+1
print("it is a palindrome")
您在最后一次打印调用之前缺少 space,因此它是在 while 循环终止后调用的。
更新:
Python 对间距敏感,我看不出您的评论中是否已修复此问题。试试这个:
x=input("Enter the word or sentance :")
a=len(x)
if a==1:
print("it is a one letter palindrome")
elif a>1:
y=0
while y<(a/2):
if x[y]==x[-(y+1)]:
print(x[y])
else:
print("it is not palindrome")
break
y=y+1
print("it is a palindrome")