def mathsTest(): """Maths test module""" correct = 0 for i in range(0,10): operator = randint(0,1) operator = operators[operator] answer = -1 if operator == "+": a = randint(0,10) b = randint(0,10) answer = a+b if operator == "-": while answer < 0: a = randint(0,10) b = randint(0,10) answer = a-b print("\nquit) to quit to main menu\n") valid = False while not valid: user = input("What is {}{}{}?: ".format(a,operator,b)) if "help" in user: if Help("Maths Test") == 1: return if "h" in user: if Help("Maths Test") == 1: return if "quit" in user: return if "q" in user: return try: user = int(user) valid = True except ValueError: valid = False if user == answer: clear("Well done!") correct += 1 else: clear("Unlucky! The answer was {}".format(answer)) if correct == 5 and correct == 6: input("\n\nYou got {}/10, well done!".format(correct)) elif correct == 7 and correct == 8: input("\n\nYou got {}/10, really well done!".format(correct)) elif correct == 9: input("\n\nYou got {}/10, Great work!".format(correct)) elif correct == 10: input("\n\nYou got {}/10, Amazing!!".format(correct)) else: input("\n\nYou got {}/10 ".format(correct))
def games(): """Games menu, used to redirect the user to the various games""" msg = "" while True: clear(msg) msg = "" print("Games") print("=====") print("\n1) Hangman") print("2) Higher or lower") print("3) Riddle of the day") print("4) Number guess") print("\nhelp) Ask at any time for help") print("quit) Quit program") ui = input("\nEnter your selection :")[0] if "q" in ui: return elif "h" in ui: if Help("Games") == 1: return elif "1" in ui: if hangman() == 1: return elif "2" in ui: if highLow() == 1: return elif "3" in ui: if riddle() == 1: return elif "4" in ui: if numberGuess() == 1: return
def main(): """Main nmodule, this is the entry point for the project, and also contains the main menu""" msg = "" while True: clear(msg) msg = "" print("Main Menu") print("=========") print("\n1) Workbook") print("2) Todays Classes") print("3) Maths Test") print("4) Games") inputting = True while inputting: try: ui = input("\nEnter your selection:\n\n").lower()[0] inputting = False except IndexError: clear(msg) print("Main Menu") print("=========") print("\n1) Workbook") print("2) Todays Classes") print("3) Maths Test") print("4) Games\n") print("You didn't input anything last time, lets try again :)") continue if "q" in ui: quit() elif "h" in ui: Help("Main Menu") elif "1" in ui: workbook() elif "2" in ui: classes() elif "3" in ui: mathsTest() elif "4" in ui: games() else: msg = "I'm sorry, that selection doesn't match any of the options. Press Enter to continue:" continue
def highLow(): """Higher or Lower game module""" score = 0 while True: number = randint(0, 100) nextNumber = randint(0, 100) clear("") print("quit) quit to main menu\n") answer = input( "The number is {}, will the next one be higher or lower?: ".format( number)) if "q" in answer: return if "help" in answer: if Help("Higher or Lower") == 1: return 1 continue elif "h" in answer: if number < nextNumber: score += 1 if score == 3: print("Well done, you have won!") else: print("Well done! you have got {} in a row, get 3 to win". format(score)) else: score = 0 print("Unlucky, keep trying!") elif "l" in answer: if number > nextNumber: score += 1 if score == 3: print("Well done, you have won!") else: print("Well done! you have got {} in a row, get 3 to win". format(score)) else: score = 0 print("Unlucky, keep trying!") input("Press Enter to continue") if score == 3: return
def riddle(): """Riddle of the day module""" clear("") riddle = riddles[randint(0, 2)] tries = 0 while tries < 5: answer = input(riddle[0] + "\n") if "quit" in answer: quit() if "help" in answer: if Help("Riddle of the day") == 1: return 1 if answer.lower() == riddle[1].lower(): print("Well done! that is the right answer!") input("") return else: print("Unlucky, try again!\n") tries += 1 print("Unlucky, the answer was {}!".format(riddle[1]))
def numberGuess(): """Number guess game module""" number = randint(0,100) guessed = False guesses = 0 while not guessed: user = input("Guess your number between 0 and 100: ") if "help" in user: if Help("Number Guess") == 1: return 1 if "q" in user: return user = int(user) guesses += 1 if user < number: print("Higher") elif user > number: print("Lower") elif user == number: print("Congratulations! you got it right in {} guesses".format(guesses)) input("") guessed = True return
def classes(): """Classes module, for students to see and update the day's classes""" classesFile = open("classes.txt", "r") currentClasses = classesFile.read().split("\n") undoClasses = [] for eachClass in currentClasses: undoClasses.append(eachClass) classesFile.close() classesFile = None while True: clear("") print("Classes") print("=======") print("\n\nYour classes for today are: \n") for i in range(1, 5): print("{}) {}".format(i, currentClasses[i - 1])) print("\nupdate) update your classes") print("accept) accept changes") print("delete) delete changes") print("quit) main menu") try: user = input("\n")[0] except IndexError: continue if "h" in user: if Help("Classes") == 1: return if "a" in user: acceptChanges(currentClasses) continue if "d" in user: currentClasses = undoChanges(undoClasses) continue if "q" in user: return if "u" in user: print("Classes") print("=======") print("\n\nYour classes for today are: ") i = 0 clear("") for i in range(1, 5): print("{}) {}".format(i, currentClasses[i - 1])) userA = input("\nplease select which one you need to update: \n\n") if userA == "q": return if userA == "quit": return if userA == "h": if Help("Classes") == 1: return if userA == "help": if Help("Classes") == 1: return userA = int(userA) - 1 j = 0 clear("") for eachAllclass in allClasses: if j < len(allClasses) - 1: j += 1 print("{}) {}".format(j, eachAllclass)) userB = input("please select which one you need to update to: ") if userB == "q": return if userB == "quit": return if userB == "h": if Help("Classes") == 1: return if userB == "help": if Help("Classes") == 1: return userB = int(userB) - 1 currentClasses[userA] = allClasses[userB]
def workbook(): """Workbook module, the projects main word processing function. Makes use of wordModule and spellModule. Calculations are carried out within this module""" historyFile = open("history.txt", "r") history = historyFile.read() historyFile.close msg = "" while True: clear(msg) msg = "" print("history: \n" + history) print("Workbook") print("========") try: ui = input("\nEnter calculations (ie. 7*3) or just write notes :)\n\n") except IndexError: continue if "quit" == ui: return if "q" == ui: return if "h" == ui: if Help("Workbook") == 1: return continue if "help" == ui: if Help("Workbook") == 1: return continue isCalc = True for char in ui: if char.isalpha(): isCalc = False if isCalc: if "+" in ui: a = float(ui.split("+")[0]) b = float(ui.split("+")[1]) c = a+b st = "{}+{}={}\n".format(a, b, c) st = st.replace(".0", "") history += st print(st) elif "-" in ui: a = float(ui.split("-")[0]) b = float(ui.split("-")[1]) c = a-b st = "{}-{}={}\n".format(a, b, c) st = st.replace(".0", "") history += st print(st) elif "*" in ui: a = float(ui.split("*")[0]) b = float(ui.split("*")[1]) c = a*b st = "{}*{}={}\n".format(a, b, c) st = st.replace(".0", "") history += st print(st) elif "/" in ui: a = float(ui.split("/")[0]) b = float(ui.split("/")[1]) c = a/b st = "{}/{}={}\n".format(a, b, c) st = st.replace(".0", "") history += st print(st) else: ui = spell(ui) ui = word(ui) history += ui + "\n" historyLines = history.count("\n") while historyLines > 19: found = history.find("\n", 2) history = history[found:] historyLines = history.count("\n") historyFile = open("history.txt", "w") historyFile.write(history) historyFile.close
def hangman(): """Hangman game module""" words = ["blaze", "skate", "eagle", "chill"] word = words[random.randint(0, 3)] playing = True guesses = 0 wrongGuesses = 0 hidden = [] guessedLetters = [] hanger = [ """ """, """ =================""", """ || || || || || || || =================""", """ ======= || || || || || || =================""", """ ======= || || || || /|| //|| =================""", """ ======= || || || || /||\ //||\\\\ =================""", """ ======= ||// ||/ || || /||\ //||\\\\ =================""", """ ======= ||// | ||/ || || /||\ //||\\\\ =================""", """ ======= ||// | ||/ O || --:-- || n /||\ / \ //||\\\\ =================""", ] for letter in word: hidden.append("-") while playing: print(hanger[wrongGuesses]) if wrongGuesses == 8: print("Unlucky, the word was " + word + " better luck next time!") input("") playing = False continue display = "Display: " hiddenStr = "" for letter in hidden: hiddenStr += letter print(display + hiddenStr) if hiddenStr in word: print( "Congratulations, you have won! The word was {} and it took {} guesses" .format(word, guesses)) input("") playing = False continue valid = False while not valid: repeat = False guess = input("Enter letter to guess: ") if "help" in guess: if Help("Hangman") == 1: return 1 guess = guess[0] for letter in guessedLetters: if guess is letter: repeat = True print("You already tried that letter, try again :)") if not repeat: valid = True guessedLetters.append(guess) i = 0 correct = False for letter in word: if guess in letter: hidden[i] = guess correct = True i += 1 if not correct: wrongGuesses += 1 guesses += 1