以防万一有人接受了这个,我去找了答案。所以我正在开展一个小型的个人项目,我陷入了困境(只是你知道我对Python很新)。我会告诉你我的意思
joke = input("Want to hear a funny joke?\n")
if joke in ['yes', 'ya', 'sure', 'ok', 'fine', 'yeah']:
chicken = input("Why did the chicken cross the road?\n")
if chicken in ["To get to the other side", "to get to the other side"]:
print("HAHAHAHAHAHHAHH OMG LOLZZZ FUNNY JOKE RIGHT!!!!!!!")
else:
print("Awww..")
我想要在这里发生的事情是python会问你是否想听一个笑话,如果你说不会它会去“Awww ..”如果你说是,它会问你为什么会这样做鸡过马路。当我说是,但当我说不,它给出了这个
Want to hear a funny joke?
no
Traceback (most recent call last):
File "C:\Users\Andrew\Desktop\Python projects\Python Buddie.py", line 34, in <module>
if chicken in ["To get to the other side", "to get to the other side"]:
NameError: name 'chicken' is not defined
我已经定义了鸡肉,你可以看到。我觉得订单错了,有人可以帮我吗?
答案 0 :(得分:2)
Consultation.where("user_id @> ARRAY[?]", current_user.id)
如果if joke in ['yes', 'ya', 'sure', 'ok', 'fine', 'yeah']:
chicken = input("Why did the chicken cross the road?\n")
if chicken in ["To get to the other side", "to get to the other side"]:
print("HAHAHAHAHAHHAHH OMG LOLZZZ FUNNY JOKE RIGHT!!!!!!!")
不 joke
会怎样?
然后没有定义in ['yes', 'ya', 'sure', 'ok', 'fine', 'yeah']
。您应该在第一个chicken
中包含第二个if
,或者事先定义if
:
chicken
或
if joke in ['yes', 'ya', 'sure', 'ok', 'fine', 'yeah']:
chicken = input("Why did the chicken cross the road?\n")
if chicken in ["To get to the other side", "to get to the other side"]:
print("HAHAHAHAHAHHAHH OMG LOLZZZ FUNNY JOKE RIGHT!!!!!!!")
答案 1 :(得分:0)
你把别人放在错误的地方,这就是
的原因当用户已经说“是”
时,您的其他声明就会出现解决此问题:
joke = input("Want to hear a funny joke?\n")
if joke in ['yes', 'ya', 'sure', 'ok', 'fine', 'yeah']:
chicken = input("Why did the chicken cross the road?\n")
if chicken in ["To get to the other side", "to get to the other side"]:
print("HAHAHAHAHAHHAHH OMG LOLZZZ FUNNY JOKE RIGHT!!!!!!!")
else:
print("Awww..")
答案 2 :(得分:0)
Python没有提供大括号来指示类和函数定义或流控制的代码块。代码块由行缩进表示,这是严格执行的。
错误只是因为错误的缩进。
ADD IN BOOK LIST