I'm a newbie trying to teach myself Python. Could somebody tell me if there is a better way to write this? I am also curious as to whether or not there is anything I should not do. This code does work, but some indentation may have been lost when I pasted it.
import random def game(): yes = ['y', 'Y', 'Yes', 'yes'] number = random.randint(1, 20) numAttempts = 0 print('') name = input('What is your name? ') print('') print('Nice to meet you', name, '! I am going to guess a random number! You will have 3 tries to guess it. ' 'Good luck!') while numAttempts < 3: print('') guess = int(input('Guess the number I have chosen between 1 and 20. ')) numAttempts += 1 if guess == number: print('') print('You guessed correctly! The number was', number, "!", 'Great Job', name, '!') break elif guess > number: print('') print('The number is lower than', guess, "!") elif guess < number: print('') print('The number is Higher than', guess, "!") else: print('') print('Sorry, the number I chose was', number, 'but you have used all 3 tries', name, '!') print('') gameover = input("Would you like to play again? Yes or No? ") while gameover in yes: game() else: print('') print('You should have chose yes. You computer will now explode!') game()