SHARE
TWEET

CS HW 2 #6

a guest Oct 17th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Write your code here
  2. from random import randint
  3.  
  4. guess = False
  5. user = 0
  6. count = 0
  7. ans = randint(1, 100)
  8. print('---------------------------------------------')
  9. print("I am thinking of a number between 1 and 100.")
  10. print("Can you guess what the number is?")
  11. print('---------------------------------------------')
  12.  
  13. while guess == False:
  14.     user = int(input("Enter your guess: "))
  15.     if user < 0 or user > 100:
  16.         print('You have entered an invalid integer')
  17.     else:
  18.         if user == ans:
  19.             count += 1
  20.             print("You guessed it in %d guesses!" % (count))
  21.             print('---------------------------------------------')
  22.             break
  23.         if user >= (ans - 10) and user <= (ans + 10):
  24.             count += 1
  25.             print('hot')
  26.             print('---------------------------------------------')
  27.         elif user < ans or user > ans:
  28.             count += 1
  29.             print('cold')
  30.             print('---------------------------------------------')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top