为了使游戏重新显示正确的猜测,需要进行哪些更改?

时间:2018-12-19 17:58:42

标签: python python-3.x

正在寻找有关如何修复我的代码的一些建议。一切正常,但我猜数字正确时计算机无法识别。有帮助吗?

# Simple guessing game

import random

import win32com.client as wincl
speak = wincl.Dispatch("SAPI.SpVoice")

game_running = True

guess2 = False
guess3 = False


while game_running == True:

    if game_running == False:
        break

    print('Welcome to my guessing game, where you will try to guess which number I am thinking of.')
    speak.Speak('Welcome to my guessing game, where you will try to guess which number I am thinking of.')

    print('You will have 3 guesses.')
    speak.Speak('You will have 3 guesses.')

    random_number = random.randint(1, 10)


    speak.Speak('Try to guess my number')
    guess1 = input('Number: ')



    if guess1 == random_number:
        print('Wow. You can read my mind')
        speak.Speak('Wow. You can read my mind.')
        game_running = False


    if guess1 != random_number:
        print('No, try again.')
        speak.Speak('No, try again.')
        guess2 = True

    if guess2 == True:
        if random_number <= 5:
            print('The number is less than 5.')
            speak.Speak('The number is less than 5.')
        else:
            print('The number is greater than 5.')
            speak.Speak('The number is greater than 5.')

        input('Number: ')

    if guess2 == random_number:
        print('That is correct! You can read my mind. Congratulations.')
        speak.Speak('That is correct! You can read my mind. Congratulations.')


    if guess2 != random_number:
        print ('No, try again.')
        speak.Speak('No, try again.')

        guess3 = True


    if guess3 == True:
        print('This is your last chance.')
        speak.Speak('This is your last chance.')

        if random_number % 2 == 0:
            print ('It is an even number.')
            speak.Speak('It is an even number.')
            input('Number: ')
        elif random_number % 2 != 0:
            print ('It is an odd number.')
            speak.Speak('It is an odd number.')
            input('Number: ')

    if guess3 == random_number:
        print('You got it!')
        speak.Speak('You got it!')

    else:
        print('No. You are out of chances.')
        speak.Speak('No. You are out of chances.')

    if guess3 != random_number:
        print('My number was ' + str(random_number))
        speak.Speak('My number was ' + str(random_number))
        game_running = False

    speak.Speak('Would you like to play again? Press y for yes or n for no.')
    play_again = input('Would you like to play again? Press y for yes or n for no: ')
    game_running = False

    if play_again == 'y' or 'yes':
        game_running = True

    if play_again == 'n' or 'no':
        print('Thanks for playing.')
        speak.Speak('Thanks for playing.')
        game_running = False

0 个答案:

没有答案