# # Math Quiz Plus # # By Sam DiBattista # import random #import os # # Constants for the program # FIRST_NUMBER_LIMIT = 1000 SECOND_NUMBER_LIMIT = 100 ADD = 0 SUBTRACT = 1 MULTIPLY = 2 DIVIDE = 3 problemList = [] # # the print math symbols # symbols = ["+", "-", "x", chr(247)] # # main method to call # def mathGame(): mainLoop() # # The main game loop # def mainLoop(): done = False while not done: problemList.clear() printInstructions() userInput = getYesNoAnswer() if userInput.upper() == "Y": for num in range(10): op = random.randint(0, 4) firstNum = random.randint(0, FIRST_NUMBER_LIMIT) secondNum = random.randint(0, SECOND_NUMBER_LIMIT) handleDivision() done = True def handleDivision(): print("Handle Division") # # Generic method to get yes or no # def getYesNoAnswer(): userAnswer = input() while userAnswer.upper() != "Y" and userAnswer.upper() != "N": print("Oops! I didn't understand your answer.") print("It should be Y for Yes and N For No. Please try again") userAnswer = input() return userAnswer # # print the screen instructions # def printInstructions(): #os.system(iif(os.name == "posix", "clear","cls")) print("Welcome to the Math Quiz!") print("+ is Add - is Subtract x is Multiply " + chr(247) + " is Divide") print("Are you ready???") # # inline if # def iif(cond, truepart, falsepart): if cond: return truepart else: return falsepart # # fire it up! # mathGame()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question