python - "Horse" Math game -


for computer science class final, have been instructed make our own game in python.

requirements:
1. needs use both “while loop” , “for x in y loop.”
2. needs use list either keep track of information or score
3. needs use function gameplay, tracking score, both.
4. display art either @ beginning, after, or in between turns.
5. can multi player or single player.
6. must carry complexity commensurate final project.

anyways, decided make game similar horse in basketball. object of game find answer of math problem before time runs out. if don't, letter in horse. once letters of horse, game over.

here have far:

import random import time timeit import default_timer  print("welcome jared's math horse game!")  time.sleep(1)  print("you have basic geometry , algebra problem,and brain teasers...")  time.sleep(1)  print("for each wrong, letter, , spell 'horse'. once letters, lose. round nearest integer!!!!!!!!")  time.sleep(1) ###begin actual stuff how_long = int(input("how many times(problems) want play? (above or equal 5)")) score = 0 ##problems problems = ["a cylinder has radius of 5. it's height 6. volume?471","a boy buys 2 shirts. 1 costs $15 , pays $27 both shirts. how 2nd shirt?12","dat boi costs $12 after 15% discount. original price?14.12","a square pyramid height 12 , side length 5. volume?20","what square root of 36?", "what roman numeral 500? quick use google!!!d","on scale of 100-100 how cool jared?100"  ]   #######end of variables ####func time     def horse(score,problem,speed):     b = input("you have {} seconds. press enter begin. round answers nearest integer.".format(speed))     begin = default_timer()     howfast = default_timer() - begin     print(random.problem[0,7])     ##check answer     answer = input("what answer?:")     ## give score   ##loops x in how_long:     while true:     if score !=5:         = random.randint(0,7)         problem = problems[a]         ##speed     speed = int(input("how fast want 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 perfect score. work.")     if score == 1:         print("you have 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 

horse()

so. i'm not sure how make if type in correct answer, won't letter, , move on. tried used 'if and' statement , it. btw, answers problems @ end. very appreciated. sorry if didn't explain well, noob @ this. haha

that data structure disaster. better off doing this. keep dict of problem : correctanswer random key, ask user input , time it. still need implement horse logic though.

score = 0 maxtime = 3 #how many milliseconds user has answer question right problems = {             "a cylinder has radius of 5. it's height 6. volume?" : "471",             "a boy buys 2 shirts. 1 costs $15 , pays $27 both shirts. how 2nd shirt?" : "12",             "dat boi costs $12 after 15% discount. original price?" : "14.12",             "a square pyramid height 12 , side length 5. volume?" : "20",             "what square root of 36?" : "6",             "what roman numeral 500? quick use google!!!" : "d",             "on scale of 100-100 how cool jared?" : "100"             }   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 , totaltime < maxtime:         print("correct!, took", totaltime, "ms answer")         score += 1     elif answer != correctanswer:         print("incorrect!, correct answer was", correctanswer)     elif totaltime > maxtime:         print("correct, took", totaltime, "ms answer allowed", maxtime, "ms") 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -