Esempio n. 1
0
def play_game():
    ''' Plays one interactive game of bulls and cows on the console'''

    # Run generate_secret to create the computer's number, answer
    answer = bc.generate_secret()

    # When the game is over, end_game = T, otherwise end_game = F
    end_game = 'F'

    # Count the number of guesses, guess_counter
    guess_counter = 0

    # Continue running the game until the player's guess matches the answer
    while end_game == 'F':

        # Take input from the player for the guess, guess
        guess = input('Enter your guess.  ')

        # Increment the number of guesses
        guess_counter += 1

        # If the answer matches the guess, end the game
        if answer == guess:
            print('Congratulations, you win!')
            print('Number of guesses: ' + str(guess_counter))
            end_game = 'T'

        # If the answer does not match, print the number of bulls and cows
        else:
            bulls = str(bc.how_many_bulls(answer, guess))
            cows = str(bc.how_many_cows(answer, guess))

            print('Number of bulls: ' + bulls)
            print('Number of cows: ' + cows)
Esempio n. 2
0
def play_game():

    guess = 0
    attempts = 0
    answer = bc.generate_secret()
  
    while not(bc.how_many_bulls(answer, guess) == 4):
        guess = input("Guess a four digit number: ")
        
        # ensure guess is 4 digits
        if len(guess) == 4:
            bc.how_many_bulls(answer, guess)
            bc.how_many_cows(answer, guess)
            
            # shows player their current bulls and cows counts
            print("Your number", guess, "has", bc.how_many_bulls(answer, guess), \
            "bulls and", bc.how_many_cows(answer, guess), "cows.")
            
            # keep track of attempts
            attempts = attempts + 1
        else:
            print("That wasn't four digits. Attention to detail goes a long way! Try again.")
            
    if attempts == 1:
        print("You guessed correctly on your first try. Stop cheating, cheater.")
    else:
        print("Finally! It took you", attempts,"attempts. You suck!")
Esempio n. 3
0
def play_game():
    ''' Plays one interactive game of bulls and cows on the console'''
    answer = str(bc.generate_secret())
    count = 0
    bulls = 0
    while (bulls < 4):
        guess = str(input('Take a guess '))
        print(guess)
        bulls = bc.how_many_bulls(answer, guess)
        cows = bc.how_many_cows(answer, guess)
        print("You got", bulls, "bulls")
        print("You got", cows, "cows")
        if (bulls < 4):
            print("Take another guess")
        count = count + 1
    print("Congratulations")
    print("You have guessed", count, "times")
Esempio n. 4
0
def play_game():
    answer = bc.generate_secret()
    '''print("answer is", answer) print answer for testing purposes'''
    guess = input("What is your guess?: ")

    attempts = 0
    while guess != answer:
        bc.how_many_bulls(answer, guess)
        bc.how_many_cows(answer, guess)
        print("Try again!")
        attempts += 1
        print("Attempts:", attempts)
        guess = input("What is your guess?: ")
        ''' This allows the user to guess again'''

    if guess == answer:
        print("Your answer", guess, "was correct!")
        print("Attempts:", attempts + 1)
Esempio n. 5
0
def play_game():
    # plays one interactive game of bulls and cows on the console
    answer = bc.generate_secret()
    # secret number created by Computer
    guess = check_4digit(input('Guess a 4-digit secert number:'))
    # ask players to input number and check if the input is correct
    #   by using check_4digit funciton

    found = False  # secret number is not yet found
    sucker = False  # player is still playing (when ask if they want to continue with y/n)
    times = 0  # to record how many times has a player guessed

    while not found and not sucker:
        print(bc.how_many_bulls(answer, guess), 'bull(s)')
        # check how many bulls
        print(bc.how_many_cows(answer, guess), 'cow(s)')
        # check how many cows
        times = times + 1
        # increment number of guessess
        if answer == guess:
            found = True
            print('Congrats! You got it! (After ' + str(times) +
                  ' guess(es).)')
        else:
            guess_again=input('Too bad, '+ str(times) +' guess(es) so far!'\
            'Would you like to guess again? (y/n)')

            while True:  # check if the input is y/n
                if guess_again == 'y':
                    guess = check_4digit(input(str('Try a different 4-digit'\
                    'number:')))
                    # ask players to input number and check if the input is correct
                    #   by using check_4digit funciton
                    break
                elif guess_again == 'n':
                    sucker = True
                    break
                else:
                    guess_again = input('I don\'t understand you.'\
                    'Would you like to guess again? y/n?')
                    next
        next