Facebook
From samuelschofield, 2 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 70
  1. #samuel schofield
  2. from random import*
  3. def cleandivide(number1,number2):
  4.         clean=False
  5.         if number1%number2==0:
  6.                 clean=True
  7.         else:
  8.                 clean=False
  9.         return clean
  10.        
  11. score=0
  12. questioncount=1
  13. print("welcome to brain training")
  14. questionnum=int(input("how meny questions do you want"))
  15. print("you will be asked ",questionnum," questions")
  16. name=input("enter your name")
  17. nickname=input("what is your nickname")
  18. print("ok ",name)
  19. print("but i will call you",nickname)
  20.  
  21. while questioncount<=questionnum:
  22.         num1=randint(1,10)
  23.         num2=randint(1,10)
  24.         questionchoice=randint(4,4)
  25.         print("question",questioncount)
  26.         if questionchoice==1:
  27.                 print(num1,"+",num2,"= ?")
  28.                 answer=int(input("what is your answer"))
  29.                 companswer=num1+num2
  30.                 if answer==companswer:
  31.                         print("correct")
  32.                         score=score+1
  33.                 else:
  34.                         print("incorect")
  35.                 print("your score is",score)
  36.         if questionchoice==2:
  37.                 print(num1,"-",num2,"= ?")
  38.                 answer=int(input("what is your answer"))
  39.                 companswer=num1-num2
  40.                 if answer==companswer:
  41.                         print("correct")
  42.                         score=score+1
  43.                 else:
  44.                         print("incorect")
  45.                 print("your score is",score)
  46.         if questionchoice==3:
  47.                 print(num1,"*",num2,"= ?")
  48.                 answer=int(input("what is your answer"))
  49.                 companswer=num1*num2
  50.                 if answer==companswer:
  51.                         print("correct")
  52.                         score=score+1
  53.                 else:
  54.                         print("incorect")
  55.                 print("your score is",score)
  56.         if questionchoice==4:
  57.                 clear=False
  58.                 while clear==False:
  59.                         clear=cleandivide(num1,num2)
  60.                         if clear==False:
  61.                                 num1=randint(1,10)
  62.                                 num2=randint(1,10)
  63.                 print(num1,"/",num2,"= ?")     
  64.                 answer=int(input("what is your answer"))
  65.                 companswer=num1/num2
  66.                 if answer==companswer:
  67.                         print("correct")
  68.                         score=score+1
  69.                 else:
  70.                         print("incorect")
  71.                 print("your score is",score)
  72.         questioncount=questioncount+1
  73. print("your final score is",score)
  74. prevhighscore = open("highscorefile.txt", "r")
  75. prevscore = int(prevhighscore.readline())
  76. prevhighscore.close()
  77. if prevscore<score:
  78.         newscore=str(score)
  79.         prevhighscore = open("highscorfile", "w")
  80.         prevhighscore.write(newscore)
  81.         prevhighscore.write(nickname)
  82.         print("congratulations",nickname,"you got a new high score")