gcman96

Multiplication Problems Script

Jan 16th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. from random import randint
  2.  
  3. def getLow():
  4.     print ''
  5.     return int(raw_input("Enter low: "))
  6.  
  7. def getHigh():
  8.     return int(raw_input("Enter high: "))
  9.  
  10.  
  11. def makeProblems(low, high):
  12.  
  13.     print "Type \"stop\" as your answer to stop and \"reset\" to reset."
  14.  
  15.     stopBool = False
  16.     wrongList = []
  17.    
  18.    
  19.     while stopBool == False:
  20.         num1 = randint(low,high)
  21.         num2 = randint(0,10)
  22.  
  23.        
  24.         response = raw_input(str(num1) + ' X ' + str(num2) + ' = ')
  25.         answer = str(num1 * num2)
  26.         problem = str(num1) + ' X ' + str(num2) + ' = ' + answer
  27.  
  28.         if response == answer:
  29.             print "Well done!"
  30.         elif response.lower() == 'stop':
  31.             if wrongList == []:
  32.                 wrongList.append("None")
  33.             print "\n" + "You got the following wrong: \n" + "\n".join(wrongList)
  34.             print ''
  35.             stopBool = True
  36.             return False
  37.         elif response.lower() == 'reset':
  38.             return True
  39.         else:
  40.             print 'WRONG! The correct answer was: ' + answer
  41.             wrongList.append(problem)
  42.  
  43. def getNums():
  44.     print ''
  45.     numList = []
  46.    
  47.     while True:
  48.         inputNum = raw_input("Enter one of the numbers.  Type 'done' to continue: ")
  49.  
  50.         if inputNum.lower() == 'done':
  51.             break
  52.         else:
  53.             numList.append(inputNum)
  54.  
  55.     print '\n' + "You have selected numbers: " + ", ".join(numList)
  56.    
  57.     return numList
  58.  
  59.  
  60. def makeSpecifs(x):
  61.  
  62.     print '\n' + "Type \"stop\" as your answer to stop and \"reset\" to reset."
  63.  
  64.     stopBool = False
  65.     wrongList = []
  66.    
  67.    
  68.     while stopBool == False:
  69.         num1 = int(x[randint(0,len(x) - 1)])
  70.         num2 = randint(0,10)
  71.  
  72.        
  73.         response = raw_input(str(num1) + ' X ' + str(num2) + ' = ')
  74.         answer = str(num1 * num2)
  75.         problem = str(num1) + ' X ' + str(num2) + ' = ' + answer
  76.  
  77.         if response == answer:
  78.             print "Well done!"
  79.         elif response.lower() == 'stop':
  80.             if wrongList == []:
  81.                 wrongList.append("None")
  82.             print "\n" + "You got the following wrong: \n \n" + "\n".join(wrongList)
  83.             print ''
  84.             stopBool = True
  85.             return False
  86.         elif response.lower() == 'reset':
  87.             return True
  88.         else:
  89.             print 'WRONG! The correct answer was: ' + answer
  90.             wrongList.append(problem)
  91.  
  92.  
  93.  
  94.  
  95. running = True
  96.  
  97. while running:
  98.    
  99.     print ''
  100.  
  101.     whatMode = raw_input('Which mode? (Range or Number): ')
  102.  
  103.  
  104.  
  105.     if whatMode.lower() == 'range':
  106.  
  107.         running = makeProblems(getLow(),getHigh())
  108.        
  109.     elif whatMode.lower() == 'number' or whatMode.lower() == 'num':
  110.    
  111.         running = makeSpecifs(getNums())
  112.  
  113.  
  114. #testestsetststestest
  115. #This comment made in neutron drive
Advertisement
Add Comment
Please, Sign In to add comment