我正在尝试用 Python 编写一个 Heads Or Tails 程序。我是一个新手,刚刚接触Python。我试图实现的目标是让程序在我不知情的情况下选择正面或反面(是的,导入随机
等)并且我想在猜测时尝试一下。这是我迄今为止所取得的成就,但与我所寻求的还不是很接近。有什么想法吗?我尝试实现在 Python 网站上找到的不同随机参数,但它们不起作用(例如用于整数的 randint
)...谢谢!
print """
Welcome to our game. This is a heads or tails game and you will be the one who gets to pick a possible answer. Lets begin!
"""
print "~-~-~-~-" * 10
theirGuess = raw_input("Whats your guess? : ")
ourAnswer = "Heads" # For Debugging purposes to check if the program works
notCorrectAnswer = "Tails" # To eliminate the possibility of not being either tails or heads in case of mistaken answer
if theirGuess == ourAnswer:
print "You got it!"
elif theirGuess != notCorrectAnswer and ourAnswer:
print "You didnt get it! Try entering either Tails or Heads!"
else:
print "You didnt get it! Try again next time!"
最佳答案
你应该尝试:
import random
ch = random.choice(["Heads","Tails"])
它将把“Heads”或“Tails”放入变量ch
中。尝试从中做点什么。
关于Python Heads Or Tails 程序帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33713201/