Advertisement
dronkowitz

Number Guessing Game.py

Mar 9th, 2022
1,383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import random
  2.  
  3. print("Welcome to my game, I will think of a number between 1 and 100. try and guess what the number is")
  4. playerName = input("What is your name? ")
  5. print("Hello {} it is {} to meet you".format(playerName,"nice"))
  6.  
  7. computerNumber = random.randrange(1,101)
  8. playing = True
  9. guesses = 0
  10. while playing:
  11.     print("please guess a number between 1 and 100")
  12.     playerNumber = input("what is your guess? ")
  13.  
  14.     playerNumber = int(playerNumber)
  15.     guesses = guesses + 1
  16.     if playerNumber == computerNumber:
  17.         print("that is correct")
  18.         playing = False
  19.  
  20.     elif guesses == 8:
  21.         print("You ran out of guesses")
  22.         playing = False
  23.  
  24.     if playerNumber < computerNumber:
  25.         print("that is too low")
  26.  
  27.     if playerNumber > computerNumber:
  28.         print("that is too high")
  29.  
  30.  
  31.  
  32. print("it took you {} guesses".format(guesses))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement