Skip to content

Instantly share code, notes, and snippets.

@iamshadmirza
Created February 19, 2018 14:24
Show Gist options
  • Save iamshadmirza/0bf6b6222377ae35560979a00316bb25 to your computer and use it in GitHub Desktop.
Save iamshadmirza/0bf6b6222377ae35560979a00316bb25 to your computer and use it in GitHub Desktop.
beginning with python
import random
cpunum = random.randrange(1,9)
usernum = 0
count = 0
print('guess a number between 1 and 9')
while True:
usernum = input()
count += 1
if usernum== 'exit':
break
usernum = int(usernum)
if usernum < cpunum:
print("You guessed too low ")
elif usernum > cpunum:
print(" You guessed too high")
elif usernum == cpunum:
print("You guessed right in",count,"attempts")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment