<p>我的头撞在墙上已经有几个小时了,我想弄清楚这个问题,所以我非常感谢你的帮助。我要做的是在一个Y/N问题的Y输入上循环程序,特别是当Y被输入时,我希望它以示例输出中所示的方式进行反应。在</p>
<p>这是我的代码:</p>
<pre><code>import random
def main():
name = eval(input("Hello user, please enter your name: "))
print("Hello", name ,"This program runs a coin toss simulation")
yn = input("Would you like to run the coin toss simulation?(Y/N):")
if yn == Y:
elif yn == N:
print("Ok have a nice day!")
heads = 0
tails = 0
count = tails + heads
count = int(input("Enter the amount of times you would like the coin to flip: "))
if count <= 0:
print("Silly rabbit, that won't work")
while tails + heads < count:
coin = random.randint(1, 2)
if coin ==1:
heads = heads + 1
elif coin == 2:
tails = tails + 1
print("you flipped", count , "time(s)")
print("you flipped heads", heads , "time(s)")
print("you flipped tails", tails , "time(s)")
main()
</code></pre>
<p>下面是我要查找的示例输出:</p>
^{pr2}$