Facebook
From Lewis F, 2 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 64
  1. # Lewis Forster
  2. from random import *
  3.  
  4. questionNumber = 1
  5. print("Welcome to brain training.")
  6. questionAmount = int(input("How many questions would you like to be asked?: "))
  7. name = input("Please enter your name: ")
  8. nick = input("Please enter your nickname: ")
  9. print("Okay,", name)
  10. print("But I will call you", nick)
  11. def cleanDivide(num1, num2):
  12.         if num1 % num2 == 0:
  13.                 cleanDivide = true
  14.         else:cleanDivide = false
  15. #did not get time to finish function and apply it
  16.  
  17.  
  18. while questionNumber <= questionAmount:
  19.         num1 = randint(1,10)
  20.         num2 = randint(1,10)
  21.         qChoice = randint(1,4)
  22.         question = " "
  23.         score = 0
  24.         def cleanDivide(num1, num2):
  25.                 if num1 % num2 == 0:
  26.                         cleanDivide = True
  27.                         return("Will cleanly divide")
  28.                 else:
  29.                         cleanDivide = False
  30.                         return("Will not cleanly divide")
  31.         if qChoice == 1:
  32.                 question = "+"
  33.         if qChoice == 2:
  34.                 question = "-"
  35.         if qChoice == 3:
  36.                 question = "*"
  37.         if qChoice == 4:
  38.                  question = "/"
  39.         if question == "/":
  40.                 cleanDivide(num1, num2)
  41.         print("Question", questionNumber)
  42.         print(num1, question, num2, "= ?")
  43.         answer = int(input("What is your answer? "))
  44.         computerAnswer = 0
  45.         if qChoice == 1:
  46.                 computerAnswer = num1 + num2
  47.         if qChoice == 2:
  48.                         computerAnswer = num1 - num2
  49.         if qChoice == 3:
  50.                 computerAnswer = num1 * num2
  51.         if qChoice == 4:
  52.                         computerAnswer = num1 / num2
  53.         if computerAnswer != answer:
  54.                         print("That is incorrect!")
  55.         else:
  56.                         print("Well Done!")
  57.                         score = score + 1
  58.         print("Your Score is:", score)
  59.         questionNumber = questionNumber + 1
  60.