Oct-24-2019, 12:18 AM
hello everyone...
here is a simple game of guessing a number from 0 to 100
you can guess computer number or have computer guess your number...
i didn't do any input validations cause... i'm lazy?
any way here is the code:

here is a simple game of guessing a number from 0 to 100
you can guess computer number or have computer guess your number...
i didn't do any input validations cause... i'm lazy?
any way here is the code:
import os import random import time width = os.get_terminal_size().columns # turns = 10 def clear(): return os.system('cls') def opening(): turns = 10 print("GUESS MY NUMBER GAME".center(width)) print() print("PRESS 1. TO GUESS COMPUTER NUMBER (BETWEEN 0-100) OR 2. TO HAVE THE COMPUTER GUESS YOUR NUMBER BETWEEN (0-100)".center(width)) print() option1 = int(input("> ")) clear() if option1 == 1: comp_num(turns) elif option1 == 2: human_num(turns) def comp_num(turns): print("GUESS THE COMPUTER NUMBER... PRESS ANY KEY TO COMTINUE...".center(width)) a = input() num1 = random.randint(0, 100) in_game = True while in_game == True: print( f"YOU HAVE {turns} TO GUESS THE NUMBER OF THE COMPUTER THAT IS BETWEEN 0-100".center(width)) guess1 = input("> ") if int(guess1) < num1: print( f"COMPUTER NUMBER IS LARGER THEN {guess1}") elif int(guess1) > num1: print( f"COMPUTER NUMBER IS SMALLER THEN {guess1}") elif int(guess1) == num1: print("CORRECT! YOU GUESSED THE NUMBER!") in_game = False # a = input("press any key to continue to next guess") turns -= 1 # clear() if turns <= 0: print("TEN TURNS PASSED GAME OVER") in_game = False def human_num(turns): low = 0 high = 100 in_game2 = True clear() print("CHOOSE A NUMBER BETWEEN 0 AND 100".center(width)) time.sleep(4) clear() while in_game2 == True: print(f"COMPUTER HAD {turns} LEFT TO GUESS YOUR NUMBER".center(width)) guess2 = int((high + low) / 2) print(f"IS THE NUMBER {guess2} ???") print("PRESS 1 KEY IF COMPUTER GUESS IS HIGHER THEN YOUR NUMBER") print("PRESS 2 KEY IF COMPUTER GUESS IS LOWER THEN YOUR NUMBER") print("PRESS 3 KEY IF COMPUTER GUESS IS CORRECT") option2 = int(input("> ")) if option2 == 1: high = guess2 elif option2 == 2: low = guess2 elif option2 == 3: print("COMPUTER SUCCEDED IN GUESSING YOUR NUMBER!") in_game2 = False turns -= 1 if turns <= 0: print("COMPUTER RAN OUT OF TURNS! GAME OVER") in_game2 = False def main(): # turns = 10 while True: opening() option3 = input("PLAY AGAIN? (y/n): ") if option3.lower() == "n": break # elif option1 == 2: # human_num(turns) main()