Created
August 25, 2020 05:54
-
-
Save CodeArtisT75/4eae834df828236a20b1e0b9f8e71c88 to your computer and use it in GitHub Desktop.
SokanAcademy: Python - find number game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
# initiale min and max is 1 - 99 | |
minNum = 1 | |
maxNum = 99 | |
# this while loop will run until the num == YOUR NUMBER | |
while True: | |
# generate random number between min and max and print it | |
num = randint(minNum, maxNum) | |
print("your number is: " + str(num)) | |
# get the answer from user | |
print("is it correct? k=less, b=greater, d=found") | |
answer = input() | |
# check answer and: | |
# if answer == 'k' the maxNum will be set to num | |
# if answer == 'b' the minNum will be set to num | |
# if answer == 'd' the while loop will break | |
if answer == "k": | |
maxNum = num | |
elif answer == "b": | |
minNum = num | |
elif answer == "d": | |
break | |
# Just print a success message | |
print("HOORAY! i found your number :))") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment