"马"数学游戏

时间:2016-05-25 03:01:14

标签: python python-3.x math

对于我的计算机科学课程决赛,我们已被指示用Python制作我们自己的游戏。

  

要求:
  1.需要同时使用“while循环”和“for y in y循环”   2.需要使用列表来跟踪信息或得分   3.需要使用游戏功能,跟踪得分,两者   4.在转弯的开始,之后或之间显示一些艺术品   5.可以是多人或单人游戏   6.必须具有与最终项目相称的复杂性。

无论如何,我决定在篮球比赛中制作类似于马的比赛。游戏的目的是在时间用完之前找到数学问题的答案。如果你没有,你会收到一封马的信。一旦你得到所有的马字母,你的游戏就结束了。

这是我到目前为止所做的:

import random
import time
from timeit import default_timer

print("welcome to Jared's Math Horse game!")

time.sleep(1)

print("You will have to do some basic geometry and algebra problem,and some brain teasers...")

time.sleep(1)

print("For each you get wrong, you get a letter, and it will spell 'HORSE'. Once you get all letters, you lose. ROUND TO THE NEAREST INTEGER!!!!!!!!")

time.sleep(1)
###BEgin actual stuff
how_long = int(input("How many times(problems) do you want to play? (above or equal 5)"))
score = 0
##Problems
problems = ["A cylinder has a radius of 5. It's height is 6. What is the volume?471","A boy buys two shirts. One costs $15 and he pays $27 for both shirts. How much was the 2nd shirt?12","dat boi costs $12 after a 15% discount. What was the original price?14.12","A square pyramid with a height 12 and a side length 5. What is the volume?20","What is the square root of 36?", "What is the roman numeral for 500? QUICK USE GOOGLE!!!D","On a scale of 100-100 how cool is jared?100"  ]


#######End of variables
####Func time
    def horse(score,problem,speed):
    b = input("You have {} seconds. Press enter to begin. Round answers to nearest integer.".format(speed))
    begin = default_timer()
    howfast = default_timer() - begin
    print(random.problem[0,7])
    ##Check answer
    answer = input("What is your answer?:")
    ## Give score


##loops
for x in how_long:
    while True:
    if score !=5:
        a = random.randint(0,7)
        problem = problems[a]
        ##Speed
    speed = int(input("How fast do you want to play?? 1=slow 2=medium 3=FAST"))

    if speed == (1):
        speed = random.randint(30,60)
    if speed == 2:
        speed = random.randint(20,40)
    if speed == 3:
        print("spicy!")
        speed = random.randint(10,30)
        score = horse(score,problem,speed)
    if score == 0:
        print("You have a perfect score. Good work.")
    if score == 1:
        print("You have an H")
    if score == 2:
        print("You have Ho")
    if score == 3:
        print("You have Hor")
    if score == 4:
        print("You have Hors")
    if score == 5:
            print("You have Horse. Game over, loser.")
            break

马()

因此。如果你输入正确的答案,我不知道如何制作它,你不会收到一封信,然后继续前进。我试过用过&if;' if和'声明就是这样。顺便说一下,问题的答案就在最后。帮助非常赞赏。对不起,如果我没有解释清楚这一点,我就是一个菜鸟。哈哈

1 个答案:

答案 0 :(得分:1)

这种数据结构是一场灾难。做这样的事情会更好。保持一个问题的词典:correctAnswer然后得到一个随机密钥,要求一些用户输入和时间。你仍然需要实现马逻辑。

score = 0
maxTime = 3 #how many milliseconds a user has to answer the question to get it right
problems = {
            "A cylinder has a radius of 5. It's height is 6. What is the volume?" : "471",
            "A boy buys two shirts. One costs $15 and he pays $27 for both shirts. How much was the 2nd shirt?" : "12",
            "dat boi costs $12 after a 15% discount. What was the original price?" : "14.12",
            "A square pyramid with a height 12 and a side length 5. What is the volume?" : "20",
            "What is the square root of 36?" : "6",
            "What is the roman numeral for 500? QUICK USE GOOGLE!!!" : "D",
            "On a scale of 100-100 how cool is jared?" : "100"
            }


for i in range(how_long):
    startTime = time.time()
    thisProblem = random.choice(list(problems.keys()))
    answer = input(thisProblem + ": ")
    endTime = time.time()

    totalTime = round(endTime - startTime, 2)


    correctAnswer = problems[thisProblem]
    if answer == correctAnswer and totalTime < maxTime:
        print("Correct!, you took", totalTime, "ms to answer")
        score += 1
    elif answer != correctAnswer:
        print("Incorrect!, the correct answer was", correctAnswer)
    elif totalTime > maxTime:
        print("Correct, but you took", totalTime, "ms to answer but are only allowed", maxTime, "ms")