Facebook
From Mohamed Ahmed, 2 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 93
  1. #Mohamed Ahmed
  2. import random
  3.  
  4. num1 = random.randint(1,10)
  5. num2 = random.randint(1,10)
  6. questionChoice = random.randint(1,4)
  7. computerAnswer = 0
  8.  
  9. def cleanDivide(num1, num2):
  10.         computerAnswer = 0
  11.         if num1 % num2 == 0:
  12.                 print("clean divide")
  13.                 print(num1, "/", num2, "= ?")
  14.                 computerAnswer = num1 / num2
  15.                 return
  16.         else:
  17.                 computerAnswer = 0
  18.                 print("does not divide cleanly")
  19.                 print(num1, "and", num2, "did not divide cleanly.")
  20.                 while num1 % num2 != 0:
  21.                         num1 = random.randint(1,10)
  22.                         num2 = random.randint(1,10)
  23.                 computerAnswer = num1 / num2
  24.                 int(computerAnswer)
  25.                 print(num1, "/", num2, "= ?")
  26.                 return
  27.  
  28.  
  29. questionNumber = 1
  30. print("Welcome to Brain Training.")
  31. print("You will be asked any amount of  questions.")
  32. questionCount = int(input("How many questions do you want?"))
  33.  
  34. name = input("Enter your name - ")
  35. nick = input("What is your nick name - ")
  36. print("Ok", name)
  37. print("But I will call you", nick)
  38.  
  39.  
  40. while questionNumber <= questionCount:
  41.         print("Question", questionNumber)
  42.         if questionChoice == 1:
  43.                 print(num1, "+", num2, "= ?")
  44.                 computerAnswer = num1 + num2
  45.         elif questionChoice == 2:
  46.                 print(num1, "-", num2, "= ?")
  47.                 computerAnswer = num1 - num2
  48.         elif questionChoice == 3:
  49.                 print(num1, "*", num2, "= ?")
  50.                 computerAnswer = num1 * num2
  51.         else:
  52.                 cleanDivide(num1, num2)
  53.                 computerAnswer= num1 / num2
  54.                 if num1 % num2 != 0:
  55.                         num1 = random.randint(1,10)
  56.                         num2 = random.randint(1,10)
  57.                         computerAnswer= num1 / num2
  58.                 int(computerAnswer)
  59.         answer = int(input("What is your answer?"))
  60.         if answer == computerAnswer:
  61.                 print("correct")
  62.         else:
  63.                 print("incorrect")
  64.         num1 = random.randint(1,10)
  65.         num2 = random.randint(1,10)
  66.         questionChoice = random.randint(1,4)
  67.         questionNumber = questionNumber + 1