gpt4 book ai didi

Python Heads Or Tails 程序协助

转载 作者:行者123 更新时间:2023-11-28 22:40:24 24 4
gpt4 key购买 nike

我正在尝试用 Python 制作一个Heads Or Tails 程序。我是新手,刚接触 Python。我试图实现的是让程序在我不知情的情况下选择HeadsTails(是的,import random,等等)和我想在猜测时试一试。这是我到目前为止所取得的成就,但它与我正在寻找的东西并不十分接近。有什么想法吗?我已经尝试实现我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com