# File: tupleGuess.py # Author: John Park # Date: 3/08/2017 # Section: N/A # E-mail: park@umbc.edu # Description: # This file contains python code that asks the user to guess # the contents of a tuple, giving them feedback on what's correct. SENTINEL = "stop" ###################################################################### # guess() asks the user to guess the contents of a tuple, giving them # feedback for each guess, and allowing infinite guesses # Input: myTuple; a tuple containing things to be guessed # Output: correctGuesses; an int that totals the correct guesses def guess(myTuple) : correctGuesses = 0 msg = "Make a guess ('" + SENTINEL + "' to quit): " guess = input(msg) while guess != SENTINEL: if guess in myTuple : print("Good guess!") correctGuesses += 1 else: print("Sorry :-( Try again: ") guess = input(msg) return correctGuesses def main(): cnt = guess(("DOG", "CAT", "GERBIL")) print("You guessed correctly", cnt, "times") main()