Python 函数返回";无”;(代码中不使用任何奇特的函数)
我正在使用循环编写一个游戏,我的代码中没有定义任何函数,但只使用基本函数,如print()。我的代码本身确实做了它应该做的事情,但是它抛出了一个Python 函数返回";无”;(代码中不使用任何奇特的函数),python,python-3.x,loops,output,Python,Python 3.x,Loops,Output,我正在使用循环编写一个游戏,我的代码中没有定义任何函数,但只使用基本函数,如print()。我的代码本身确实做了它应该做的事情,但是它抛出了一个None,用户应该在那里输入代码 while loca == 22: if (lever=="back") and (dial=="red"): print("congratlations! You have won the game!") play=input(print("Would you like to p
None
,用户应该在那里输入代码
while loca == 22:
if (lever=="back") and (dial=="red"):
print("congratlations! You have won the game!")
play=input(print("Would you like to play again? Type 'Y' for yes and 'N' for no."))
while play in ["yes","y","Y","Yes"]:
loca = 1
play="reset"
while play in ["no","n","N","No"]:
print("Thanks for playing!")
quit()
while (not play == "reset"):
while (not play == ["no","n","N","No"]) and (not play == ["yes","y","Y","Yes"]):
play=input(print("Sorry, I didn't understand. Please enter 'Y' for yes, or 'N' for no."))
else:
print("Hmm.. You don't quite have the right combination yet!")
我知道quit()
是一个函数,但我也尝试了删除它的代码,它仍然返回None
。我写的其他程序使用的函数与我在代码中使用的函数相同,我从来没有遇到过这个问题
对于这个任务,我们应该在代码中实现quit函数,或者它的一些变体,但是我们还没有了解函数的
返回
(这个代码不应该有任何作者定义的函数),而且我在网上能找到的唯一答案似乎是关于返回
。我想我会在这里碰碰运气,也许这只是我缺少的一些小东西。函数返回print
无,然后将其传递到input
,删除对print
的调用,因为input
已经负责打印传递的字符串
而不是:
play=input(print("Would you like to play again? Type 'Y' for yes and 'N' for no."))
使用:
创建变量play
的行。如果您误用了输入函数,则会向用户显示您在函数中写入的提示。但是,通过输入print()
将返回none
这条线应该是:
play=input(“您想再次播放吗?键入'Y'表示是,键入'N'表示否”)
另外,你应该试着遵守PEP 8-python风格指南哦,哇,我怎么没有看到这一点。非常感谢你。
play=input("Would you like to play again? Type 'Y' for yes and 'N' for no.")