Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #Written Under Request
- #Python 3.1
- def compguess(usernum):
- toohigh = []
- toolow = []
- correct = False
- low = 0
- high = 0
- loopnum = 0
- while correct == False:
- loopnum = loopnum + 1
- if loopnum == 1:
- guess = random.randrange(1,1001)
- else:
- guess = random.randrange(low,high)
- print('The Computer Has Guessed:',guess)
- if guess > usernum:
- print('The Computers Guess Was Too High')
- guessedyet = False
- toohigh.append(guess)
- toohigh.sort()
- high = toohigh[0]
- if guess < usernum:
- guessedyet = False
- print('The Computers Guess Was Too Low')
- toolow.append(guess)
- toolow.sort()
- toolow.reverse()
- low = toolow[0]
- if guess == usernum:
- guessedyet = True
- print('The Computers Guess Was Correct')
- correct = True
- if guessedyet == False:
- print('Do You Want The Computer To Guess Again')
- valid = False
- while valid == False:
- print('Enter "0" For No or "1" For Yes')
- option = input(': ')
- if option in ['1','0']:
- valid = True
- else:
- print('Invalid Input')
- if option == '1':
- correct = True
- #Place Any Integer Or Variable Containing Integer In The Argument Field
- compguess(78)
Advertisement
Add Comment
Please, Sign In to add comment