Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- random_number = random.randint (1, 100)
- count = 0
- def guessing_game():
- print("Let's play a number guessing game!")
- guess = int(input('Guess a number between 1 and 100: ')
- if guess > random_number:
- print('Too high! Guess again!')
- count = count + 1
- elif guess < random_number:
- print('Too low! Guess again!')
- count = count + 1
- else:
- print('You guessed the correct number in', count, 'attempts!')
- while guess != random_number
- return guess
- def main():
- keep_playing == "y"
- while keep_playing == "y":
- guessing_game()
- keep_playing = input('Would you like to play again? Press "y" to play again or any other key to exit: ')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement