Skip to content

Instantly share code, notes, and snippets.

@ChekeGT
Created September 9, 2023 23:23
Show Gist options
  • Save ChekeGT/83cbe94c59b50c29c6d66f8fbf36d09c to your computer and use it in GitHub Desktop.
Save ChekeGT/83cbe94c59b50c29c6d66f8fbf36d09c to your computer and use it in GitHub Desktop.
A simple game in which the computer can guess a number that's on your head ;)
import random
import os
import time
def guess_the_number():
os.system('cls')
print('This program is designed to guess a number. Have fun!!!')
time.sleep(3)
low = 0
high = 10 ** 6
feedback = None
while feedback != 'y':
feedback = input(f'Is your number between {low} and {high}:\n y) It is \n x) It has a lower floor \n z) It has a higher ceiling \n')
if feedback == 'x':
low -= 10 ** 6
if feedback == 'z':
high += 10 ** 6
while feedback != 'c':
if low == high:
guess = low
else:
try:
guess = random.randint(low, high)
except ValueError:
print('Something has gone wrong. You must have missed the number, try again.')
time.sleep(2)
guess_the_number()
return
feedback = input(f"The guessed number is {guess}. Type: \n c) If it's correct \n l) If it's too low \n h) If it's too high: \n").lower()
if feedback == 'l':
low = guess + 1
if feedback == 'h':
high = guess - 1
print(f'Yaaay, the computer has guessed your number: {guess}')
guess_the_number()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment