lundi 9 août 2021

My code is not functioning the way i want to

So im practicing python by making simple games. I don't know what I did wrong here, when game over shows and I input 'yes' to play again, it breaks. That shouldn't supposed to happen. Any improvements is appreciated.

def play():
    tries = 3
    name = input('Enter your name: ')
    start = input('Hi {}! Do you want to play? (Yes/No)'.format(name.upper()))
    while True and tries > 0 and start.lower() == 'yes':
        n = input('What is the number next to 5? : ')
        try:
            i = float(n)
            if i == 6:
                print('Correct!')
                start = input('Do you want to play again? (Yes/No)')

            else:
                tries -= 1
                if tries > 1:
                    print('You have', tries, 'tries left. Try again!')
                elif tries == 1:
                    print('You only have', tries, 'try left.')
                elif tries == 0:
                    print("""It's game over for you""", name.upper())
                    start = input('Do you want to play again? (Yes/No)')
                if start.lower() == 'no':
                        print('Sorry to have you go')
                        break

        except:
            print('Please enter a number: ')
        
if __name__ == '__main__':
    play()

Aucun commentaire:

Enregistrer un commentaire