Python Heads Or Tails 程序帮助

标签 python random

我正在尝试用 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/

相关文章:

java - Java中的随机数生成以1000的倍数出现

python - scc 风格的 QPushbutton

JavaScript 伪随机序列生成器

Python pandas 插入长整数

python - 使用 Pandas 重命名数据框列中的元素

c++ - C++中的'rand'函数?

algorithm - 这个生成随机数的算法叫什么?

java - 在多线程的情况下使用流限制的最佳性能方式

python - 从数据框中删除顶部标题

python - 是否可以以编程方式(而不是从命令行)运行 manim?