def main(): goAgain = True # Loop to keep user in program. while goAgain == True: # Call the intro intro() selection() # Get user menu selection menuSelection = dmUtil.getUserInput() while menuSelection > 3 or menuSelection < 1: print( "Entered number out of bounds. Please enter a number within range." ) selection() menuSelection = dmUtil.getUserInput() if menuSelection == 1: # AnswerChecker answerChecker.answerChecker() if menuSelection == 2: # MemoryBank memoryBank.memoryBank() if menuSelection == 3: # Guess the Number guessTheNumber.guessTheNumberGame() # Ask the user if they want to repeat the program goAgain = dmUtil.goAgain()
def add(cards): print("\n[] + []") num1 = dmUtil.getUserInput() print("\n", num1," + []") num2 = dmUtil.getUserInput() print("\n", num1," + ", num2) problem = f"{num1}+{num2}" answer = num1 + num2 cards[problem] = str(answer) return cards
def sub(cards): print("\n[] - []") num1 = dmUtil.getUserInput() print("\n", num1," - []") num2 = dmUtil.getUserInput() print("\n", num1," - ", num2) problem = f"{num1}-{num2}" answer = num1 - num2 cards[problem] = str(answer) return cards
def mul(cards): print("\n[] * []") num1 = dmUtil.getUserInput() print("\n", num1," * []") num2 = dmUtil.getUserInput() print("\n", num1," * ", num2) problem = f"{num1}*{num2}" answer = num1 * num2 cards[problem] = str(answer) return cards
def doMulProblem(): correctAnswer = False print("\n[] x []") num1 = dmUtil.getUserInput() print("\n", num1, " x []") num2 = dmUtil.getUserInput() answer = num1 * num2 print("\n", num1, " x ", num2, " = ", answer, "\n")
def doSubProblem(): correctAnswer = False print("\n[] - []") num1 = dmUtil.getUserInput() print("\n", num1, " - []") num2 = dmUtil.getUserInput() answer = num1 - num2 print("\n", num1, " - ", num2, " = ", answer, "\n")
def doAddProblem(): correctAnswer = False print("\n[] + []") num1 = dmUtil.getUserInput() print("\n", num1, " + []") num2 = dmUtil.getUserInput() answer = num1 + num2 print("\n", num1, " + ", num2, " = ", answer, "\n")
def datamanCalculator(): dmUtil.returnKey() print("==================") print("DATAMAN Calculator") print("==================") progRun = True #Program loop while progRun == True: print("Let's do some math!") print("What kind of problem is it? \n1.+ \n2.- \n3.x \n4.Exit") choice = dmUtil.getUserInput() if choice == 1: doAddProblem() elif choice == 2: doSubProblem() elif choice == 3: doMulProblem() elif choice == 4: progRun = False else: print("Enter a valid option!")
def useCards(): # user is given previously input math problems # and their score cards = json.load(open('cards.txt','r')) correct = 0 incorrect = 0 total = 0 print("Ready? Go!") for key in cards: print(key) print("Answer: ") guess = dmUtil.getUserInput() if str(guess) == cards[key]: print("Correct!") correct += 1 total += 1 else: print("Incorrect!") incorrect += 1 total += 1 score = (correct / total) * 100 print("Correct: ",correct,"Incorrect: ",incorrect) if score > 90: print("Great job!") print("Score:",score,'%') elif score > 80: print("Good job!") print("Score:",score,'%') elif score > 60: print("Keep it up!") print("Score:",score,'%') else: print("Better luck next time!") print("Score:",score,'%')
def answerChecker(): dmUtil.returnKey() print("=======================") print("DATAMAN Problem Checker") print("=======================") progRun = True #Program loop while progRun == True: print("Let's check your math!") print("What kind of problem is it? \n1.+ \n2.- \n3.x \n4.Exit") choice = dmUtil.getUserInput() if choice == 1: doAddProblem() elif choice == 2: doSubProblem() elif choice == 3: doMulProblem() elif choice == 4: progRun = False else: print("Enter a valid option!")
def guessTheNumberGame(): dmUtil.returnKey() print("===================") print("DATAMAN Number Game") print("===================") # Create random number randomNumber = random.randint(1,100) # Create a counter for the number of guesses. guessCounter = 0 # Create a bool for gameover status. gameOver = False print("I'm thinking of a number...between 1 and 100....Take a guess!") # Create loop using bool to control it. while gameOver == False: # Get a guess from the user. userNumber = dmUtil.getUserInput() # Add one to the counter. guessCounter = guessCounter + 1 # Evaluate the user guess. if userNumber > randomNumber: dmUtil.returnKey() print("Too high... Try again!") elif userNumber < randomNumber: dmUtil.returnKey() print("Too Low... Try again!") else: dmUtil.returnKey() print("That's right! You guessed ", randomNumber, "in only ", guessCounter, "tries!") # Set the game over controller to end the loop gameOver = True
def popQuiz(): dmUtil.returnKey() # Bool to control game state gameLoop = True print("================") print("DATAMAN Pop Quiz") print("================") while gameLoop == True: # Generatr randoms needed for numbers and operator number1 = getRandomNumber() number2 = getRandomNumber() operator = getRandomOperator() # Assign string values for operator if operator == 0: operatorChar = "+" questionPrompt = str(number1) + " " + operatorChar + " " + str( number2) + " = " answer = number1 + number2 elif operator == 1: operatorChar = "-" questionPrompt = str(number1) + " " + operatorChar + " " + str( number2) + " = " answer = number1 - number2 else: operatorChar = "X" questionPrompt = str(number1) + " " + operatorChar + " " + str( number2) + " = " answer = number1 * number2 print(questionPrompt) userAnswer = dmUtil.getUserInput() while userAnswer != answer: print("Not quite...Try again!") print(questionPrompt) userAnswer = dmUtil.getUserInput() dmUtil.returnKey() print("That's right!") print(questionPrompt, answer) # Go again question gameLoop = again()
def main(): goAgain = True # Loop to keep user in program. while goAgain == True: # Call the intro intro() selection() # Get user menu selection menuSelection = dmUtil.getUserInput() while menuSelection > 6 or menuSelection < 1: print( "Entered number out of bounds. Please enter a number within range." ) selection() menuSelection = dmUtil.getUserInput() if menuSelection == 1: # AnswerChecker answerChecker.answerChecker() if menuSelection == 2: # Pop Quiz popQuiz.popQuiz() if menuSelection == 3: # Guess the Number guessTheNumber.guessTheNumberGame() if menuSelection == 4: #Memory bank cards = {} memoryBank.memoryBank(cards) if menuSelection == 5: # Dataman Calculator datamanCalculator.datamanCalculator() if menuSelection == 6: # Exits the program print("Goodbye!") break # Ask the user if they want to repeat the program goAgain = dmUtil.goAgain()
def doMulProblem(): correctAnswer = False print("\n[] x []") num1 = dmUtil.getUserInput() print("\n", num1, " x []") num2 = dmUtil.getUserInput() print("\n", num1, " x ", num2) answer = num1 * num2 while correctAnswer == False: print("What is the answer?") checkAnswer = dmUtil.getUserInput() if answer == checkAnswer: print("\nCorrect! Try another problem!\n") correctAnswer = True else: print("\nIncorrect! Try again!\n")
def memoryBank(): print("DATAMAN Memory Bank") print("\n1. Create \n2. Study") choice = dmUtil.getUserInput() if choice == 1: createCards() elif choice == 2: useCards() else: print("Invalid option. Try again.") memoryBank()
def createCards(cards): # creates .csv file 'deck' of cards print() print("Let's make some flashcards.") print("How many cards?") count = dmUtil.getUserInput() print() cardChoice(count, cards) json.dump(cards, open('cards.csv','w')) print(f"Your deck so far: {cards}") # visual verification of cards memoryBank(cards)
def again(): print("\nWould you like to do another one?") print("1. Yes \n2. No") choice = dmUtil.getUserInput() dmUtil.returnKey() # Repeat selection if choice == 1: return True # Quit selection elif choice == 2: return False
def answerChecker(): print("DATAMAN Problem Checker") problemRange = 10 #Sets a range for the numbers involved in the problems solved = 0 #Counter for correct answers progRun = True #Keeps the program running num1 = random.randint(0,problemRange) #First number in the problem num2 = random.randint(0,problemRange) #Second number in the problem while progRun == True: correctAnswer = False #Checks if problem was solved right problemType = random.randint(1,3) #Rolls a number that will determine the problem type if problemType == 1: solution = num1 + num2 print(num1," + ",num2," = ? ") elif problemType == 2: solution = num1 - num2 print(num1," - ",num2," = ? ") else: solution = num1 * num2 print(num1," x ",num2," = ? ") while correctAnswer == False: print("What is the answer? \n[101: Skip problem | 102: Exit] "); choice = dmUtil.getUserInput() if choice == solution: solved+=1 print("Correct! You have answered",solved,"problems correctly!") print("Goodjob!\n") correctAnswer = True elif choice == 101: print("Skipped! Correct answers reset.\n") solved = 0 correctAnswer = True elif choice == 102: correctAnswer = True progRun = False elif choice != solution: print("Incorrect! Try again.\n") num1 = random.randint(1,problemRange) num2 = random.randint(1,problemRange)
def again(): print("Would you like to study the same cards again?") print("\n1. Yes \n2. No") choice = dmUtil.getUserInput() if choice == 1: useCards(cards) elif choice == 2: print("Returning...") memoryBank(cards) else: print() print("Invalid option. Try again.")
def useCards(cards): # user is given previously input math problems # and their score cards = json.load(open('cards.csv','r')) correct = 0 incorrect = 0 total = 0 print() print("Ready? Go!") for key in cards: print(key) print("Answer: ") guess = dmUtil.getUserInput() if str(guess) == cards[key]: print() print("Correct!") correct += 1 total += 1 else: print() print("Incorrect!") incorrect += 1 total += 1 if total > 0: score = (correct / total) * 100 print() print("Correct: ",correct,"Incorrect: ",incorrect) if score > 90: print("Great job!") print("Score:",score,'%') elif score > 80: print("Good job!") print("Score:",score,'%') elif score > 60: print("Keep it up!") print("Score:",score,'%') else: print("Better luck next time!") print("Score:",score,'%') else: print() print("You can't study an empty deck!") print("Use Create Deck to get started!") again()
def deleteCards(cards): print("Are you sure you want to empty your deck?") print("THIS CANNOT BE UNDONE!") print("\n1. Yes \n2. No") choice = dmUtil.getUserInput() if choice == 1: cards = {} json.dump(cards, open('cards.csv','w')) memoryBank(cards) elif choice == 2: print("Whew... close one.") memoryBank(cards) else: print() print("Invalid option. Try again.")
def createCards(): # create array of user input math problems # for user to solve print("Let's make some flashcards.") print("How many cards?") count = dmUtil.getUserInput() # number of flashcards is set given by user print("Type the problem, hit the spacebar, type the answer, and then hit enter.") cards = dict(input().split() for _ in range(count)) # this creates a dictionary using user input # user can input problem, then a space, and then the correct answer # example: '2+2' ``space key`` '4' # this will be put into dictionary with '2+2' as the key # and '4' will be the value json.dump(cards, open('cards.txt','w')) print(cards) # for now, this verifies the user made the cards correctly memoryBank()
def cardChoice(count, cards): for i in range(count): print("For this card, choose an operator: \n1. + \n2. - \n3. *") choice = dmUtil.getUserInput() print(f"Choice was {choice}") if choice == 1: add(cards) i += i elif choice == 2: sub(cards) i += i elif choice == 3: mul(cards) i += i else: print() print("Invalid option. Try again.") cardChoice(count, cards)
def memoryBank(cards): print("") print("===================") print("DATAMAN Memory Bank") print("===================") print("\n1. Create Deck \n2. Study \n3. Empty Deck\n4. Exit") choice = dmUtil.getUserInput() if choice == 1: createCards(cards) elif choice == 2: useCards(cards) elif choice == 3: deleteCards(cards) elif choice == 4: print() print("Exiting...") else: print() print("Invalid option. Try again.") memoryBank(cards)