Python 3.4.3
(的Python 3.4.3)
I am trying to create an interactive drawing program using Python and turtle.
(我正在尝试使用Python和turtle创建一个交互式绘图程序。)
My program runs by first asking the user to specify the length of the sides of the shape. (我的程序通过首先要求用户指定形状侧面的长度来运行。)
If the length is greater than zero, the program will begin to execute. (如果长度大于零,程序将开始执行。)
I would like the program to continue running and to continue asking the user for information, up until the point the user enters the length of the sides as less than or equal to zero, at which point the program will exit.
(我希望程序继续运行并继续向用户询问信息,直到用户输入边的长度小于或等于零为止,然后程序将退出。)
I am therefore using a 'while-loop' to run the program and ask the user for specifics. (因此,我正在使用“ while循环”来运行程序并询问用户具体信息。)
I want the user to be limited to requesting one of the following three shapes;
(我希望用户仅限于请求以下三种形状之一;)
octagon, heptagon or hexagon. (八边形,七边形或六边形。)
If the user enters anything other than this, I want the program to ask the user to specify their choice of shape again. (如果用户输入了其他内容,则我希望程序要求用户再次指定其形状选择。)
Therefore, I have the following code:
(因此,我有以下代码:)
import turtle
lineLength = float(input("What length line would you like? "))
while lineLength > 0 :
print("You have choosen to draw a shape, please enter specifics:")
penColor = input("Please choose a pen color: ")
shape = input("which shape would you like to draw? ")
while shape.lower() != "octagon".lower() or shape.lower() !=
"heptagon".lower() or shape.lower() != "hexagon".lower() :
print("You have to select a shape from the specified list.")
shape = input("What shape would you like to draw: ")
Output: The actual output is that the code will run the "You have to select a shape from the specified list. What shape would you like to draw: " indefinitely;
(输出:实际输出是代码将运行“您必须从指定的列表中选择一种形状。您想绘制什么形状:”无限期;)
regardless of the input from the user. (不管用户输入什么。)
Expected Output: My aim, and what I am expecting, is for the inner while-loop to exit once the user has input either octagon, heptagon or hexagon.
(预期的输出:我的目标和期望是,一旦用户输入八边形,七边形或六边形,则退出内部while循环。)
In fact, I do not understand why the inner while-loop should run at all if the user selects one of these three shapes as the condition for the while-loop has not been met. (实际上,我不理解为什么如果用户选择这三种形状之一来满足while循环的条件,那么内部while循环为什么应该完全运行。)
ask by Andrew Hardiman translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…