我试过几件事情来解决这个循环,它只是不会工作。至于现在它给了我一个语法错误,突出显示第一个打印语句中的yes后面的引号......我没有看到任何错误吗?时髦虽然循环/时髦的语法错误Python 2.7
Ycount = 0
Ncount = 0
Valid = ["Y","y"]
InValid = ["N","n"]
Quit = ["Q","q"]
Uinp = ""
while Uinp != "Q":
Uinp = raw_input("Did you answer Y or N to the question(enter Q to quit)? ")
if Uinp in Valid:
Ycount = Ycount + 1
print "You have answered yes" ,Ycount, "times"
print "You have answered no" ,Ncount, "times"
elif Uinp in InValid:
Ncount = Ncount + 1
print "You have answered yes" ,Ycount, "times"
print "You have answered no" ,Ncount, "times"
elif Uinp in Quit:
break
很明显,它也复制了滑稽....变量在我的评论结束... – Carsomyr
您的代码适合我。 – Hoppo
什么是给你一个语法错误 - 在你的编辑器中突出显示,或者当你尝试运行时解释器?...你使用的是什么版本的Python:是2.x还是3.x? –