MacSG

IntroLab8_3

Mar 25th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import random
  2.  
  3. def getData(x,y):
  4.     return random.randint(x,y)
  5.  
  6. def inRange(n,x,y):   # x <= n <= y
  7.     return (x <= n and n <= y)
  8.  
  9. #Main Program
  10. target = getData(1,100)
  11. guess = int(input("Enter your guess: "))
  12. if inRange(guess,1,100):
  13.     if guess < target:
  14.         print("too low.")
  15.     elif guess > target:
  16.         print("too high.")
  17.     else:
  18.         print("Congrat.")
  19. else:
  20.     print("Sorry, out of range.")
Advertisement
Add Comment
Please, Sign In to add comment