Guest User

Example code with comments

a guest
Dec 2nd, 2021
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. #import the random library
  2. import random
  3.  
  4. # read a score from the keyboard
  5. print("I am thinking of a number between 1-10")
  6. print("Try to guess the number [1-10]", end="")
  7. userGuess = int(input())
  8.  
  9. # have the computer randomly pick a number from 1-10
  10.  
  11. computerNumber = random.randint(1, 10)
  12. if userGuess == computerNumber:
  13.   if userGuess == 2:
  14.     userGuess = "Jack"
  15.   print("You guessed " + str(userGuess) + " and I picked " + str(computerNumber) + ". Nice Job!") #added concatentation to not have the space before the period
  16. else:
  17.   print("\nNope, the number was", computerNumber, "and you guessed", userGuess)
  18.  
Advertisement
Add Comment
Please, Sign In to add comment