如何解决语法错误:小饰品中 main.py 中第 16 行的错误输入
import turtle
pen = turtle.Turtle()
pen.speed(10000000000)
pen.color("green","red")
pen.begin_fill()
for i in range(100):
pen.forward(209)
pen.left(421)
pen.right(312)
pen.hideturtle()
turtle.done()
o == input("Do you love it?y/n")
**if o == y:**
print"Thanks,please love for me{^-^}"
if o == n:
print"Thanks for playing{^-^}"
else:
print"I can't understand what are you saying,can you say that again?
第 16 行语法错误 我用小饰品做的 我的第一个项目 我把它放在小饰品里 在 SteamforVietNam 每周挑战
解决方法
-
==
和=
是不同的。==
用于比较。=
用于分配。 -
你使用的是 python 2.7 吗?应该是
print("I can't understand what are you saying,can you say that again?")
-
当您想比较字符串时,确保使用
' '
或" "
import turtle
pen = turtle.Turtle()
pen.speed(10000000000)
pen.color("green","red")
pen.begin_fill()
for i in range(100):
pen.forward(209)
pen.left(421)
pen.right(312)
pen.hideturtle()
turtle.done()
o = input("Do you love it?y/n")
if o == 'y':
print("Thanks,please love for me{^-^}")
elif o == 'n':
print("Thanks for playing{^-^}")
else:
print("I can't understand what are you saying,can you say that again?")
,
正如@Sujay 提到的,您有以下问题:
- 身份
- 打印语句语法
- 分配变量
此外,如果您打算以某种方式使用用户输入(不清楚您想要什么),请将其放在乌龟笔上方:
import turtle
o = input("Do you love it?y/n")
if o == "y":
print("Thanks,please love for me{^-^}")
if o == "n":
print("Thanks for playing{^-^}")
else:
print("I can't understand what are you saying,can you say that again?")
pen = turtle.Turtle()
pen.speed(10000000000)
pen.color("green","red")
pen.begin_fill()
for i in range(100):
pen.forward(209)
pen.left(421)
pen.right(312)
pen.hideturtle()
turtle.done()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。