Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #  Platon Candell
  2. #  pcandell@ucsc.edu
  3. #  programming assignment 3
  4.  
  5.  
  6. import random
  7.  
  8. secnum = random.randint(1, 10) #Generates a random number 1-10 and assigns value to x
  9. win = False
  10.  
  11. print(secnum)
  12. print()
  13. print("I'm thinking of an integer in the range 1 to 10. You have three guesses.")
  14. print()
  15.  
  16. for x in ["first", "second", "third"]:
  17.     guess = int(input("Enter your " + str(x) + " guess: "))
  18.     if guess > secnum:
  19.         print("Your guess is too high.")
  20.         print()
  21.     elif guess < secnum:
  22.         print("Your guess is too low.")
  23.         print()
  24.     elif guess == secnum:
  25.         win = True
  26.         print("You win!")
  27.         print()
  28.         break
  29.     elif x == 'third' and guess != secnum:
  30.         print("You lose. The number was " + str(secnum) +".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement