【问题标题】:Python point and guessing systemPython点和猜测系统
【发布时间】:2013-10-30 01:14:21
【问题描述】:

什么是做这个系统的好方法:

用户最多有 2 次机会回答问题。 总共有4个问题。 如果用户在第一次尝试中猜到答案,他们将获得 2 分。 如果用户在第 2 次尝试中猜到答案,他们将获得 1 分。 如果用户在 2 次机会中没有得到答案,他们将获得该问题的 0 分并继续下一个问题。 然后在所有四个问题之后,它列出了他们得到的分数/8。 (4道题,每道题2分)

我试过这个:

print("Question number one:")                                      #Question two
print("How many Call of Duty games are there?")
print("a) 4")
print("b) 6")
print("c) 2")
print("d) 8") 
question = int(input("Your answer: "))
maxGuesses = 2
guessesTaken = 0
points = 0
if question == 8:
    print("You are correct! You guessed the answer on the first try!")
    points = points + maxGuesses-guessesTaken
    print("You scored", (maxGuesses-guessesTaken), "points!")
else:
    print("Incorrect!")
    print("You have", (maxGuesses-guessesTaken-1), "guess remaining!")
    answer = int(input("Your answer: "))
    if answer == 8:
        print("You are correct!")
        points = points + maxGuesses-guessesTaken
        print("You scored", (maxGuesses-guessesTaken-1), "points!")
    else:
        print("Incorrect!")
        print("Next question!") 

但这行不通,因为如果用户第一次猜错了,第二次猜对了,它仍然算作 2 分。

【问题讨论】:

    标签: python system point


    【解决方案1】:

    您需要在他们猜测后通过执行guessesTaken = guessesTaken + 1 增加guessesTaken,或者更短的方法是执行guessesTaken += 1。希望对您有所帮助。

    【讨论】:

    • 我应该在哪里插入?
    • 伙计,这看起来像是家庭作业——你应该自己申请。尝试一下。
    • 这绝对是家庭作业 - 请参阅问题中的 #Question two 和“(4 个问题,每个问题 2 分)”。对不起 - 问你的老师!
    • 这实际上是一个作业,但是,如果我有什么不明白的地方,我应该在第二天问谁?
    猜你喜欢
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 2011-03-13
    相关资源
    最近更新 更多