我如何获得激活的第一选择? [英] How do I get the first choice to activate?
本文介绍了我如何获得激活的第一选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import sys
from random import randint
print("Choose: Y/N")
def main():
user_input = str(input("y/n"))
Choice = user_input
if Choice == "y":
loop()
if Choice == "n":
print("goodbye")
quit()
counter = 0
trials = 0
def loop():
global counter
global trials
nPeople = int(input("Enter the Number of People in the Room: "))
myBday = randint(1,365)
userInput = "y"
while userInput.lower() == "y":
for i in range (1, nPeople+1):
if myBday == randint(1,365):
counter += 1
break
trials += 1
print(counter/trials)
main()
loop()
if __name__ == "__main__":
loop()
我无法获得第一个主要选择来提示回复。
我尝试了什么:
我尝试引入更多变量。并改变一切。
I can't get the First "Main" choice to prompt a response.
What I have tried:
I have tried introducing more variables. and changing everything around.
推荐答案
你的测试结尾是错误的,__ name __
只等于__ main __
以交互方式运行,或从命令行运行。它应该是:
Your test at the end is wrong,__name__
is only equal to"__main__"
when running interactively, or from the command line. It should be:
if __name__ != "__main__":
此外还有打印行
Also the print line
print("Choose: Y/N")
应位于主函数内部,就在输入请求之前,因此用户知道它正在等待输入。
should be inside your main function, just before the input request, so the user knows that it is waiting for input.
这篇关于我如何获得激活的第一选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文