要求用户输入乌龟项目的屏幕尺寸

Asking for user to input screen size for a turtle project

我是 Python 的新手,知之甚少。我正在做一个使用海龟的项目,我需要让用户输入 window 宽度和高度,但我完全迷路了。到目前为止我已经想到了这个。

w = int(input(w))
h = int(input(h))
screen = turtle.Screen()
screen.setup(w, h, 0, 0)

我不知道我做错了什么。任何帮助都会很棒。谢谢

看起来你快到了!

import turtle

w = int(input("Enter Width: "))
h = int(input("Enter Height: "))
screen = turtle.Screen()
screen.setup(w, h, 0, 0)

您似乎忘记导入 turtle 库,另外请注意输入行。如果您只希望提示为 w 或 h,则需要用 " "

括起来