【发布时间】:2015-12-08 04:53:49
【问题描述】:
我正在为学校做作业,这个程序非常简单,但是我的 if 语句不能正常工作。有人知道为什么吗?代码如下:
letter = input("Name one of the most common letters in wheel of fortune puzzles: ")
if letter == "r":
print(letter, "is one of the most common letters!")
if letter == "s":
print(letter, "is one of the most common letters!")
if letter == "t":
print(letter, "is one of the most common letters!")
if letter == "l":
print(letter, "is one of the most common letters!")
if letter == "n":
print(letter, "is one of the most common letters!")
if letter == "e":
print(letter, "is one of the most common letters!")
else:
print("Incorrect!")
letter = input("Name one of the most common letters in wheel of fortune puzzles: ")
input("\n\nPress the enter key to exit:")
输出是:
Name one of the most common letters in wheel of fortune puzzles: j
Incorrect!
Name one of the most common letters in wheel of fortune puzzles: r
Press the enter key to exit:
【问题讨论】:
-
您需要更具体。 “不工作”是什么意思?提供样本输入和输出。此外,您的
else仅连接到最后一个if,因此如果字母不是“e”,您肯定会看到"Incorrect!"。请改用elif ... :。 -
好的,抱歉。输出是
-
我只是编辑我的原件
标签: python python-3.x if-statement