Posts

Showing posts with the label guess the number game

Guess The Number Game - You vs. Your Friend

Guess a Random Number Game import random print("\nWelcome to the Guess a random number Game!") print("Its a 2 player game.") print("The Winner is the one with the lowest attempts.\n") lower_limit = int(input("Plz choose the lower limit? ")) upper_limit = int(input("Plz choose the upper limit? ")) winner = [] for i in range(2): random_number = random.randint(lower_limit, upper_limit) print(f"\nIts player {i+1} turn:") guess_number = "" attempts = 0 while guess_number != random_number: attempts += 1 guess_number = int(input(f"Player {i+1}, Plz guess the number between {lower_limit} and {upper_limit}: ")) if guess_number < random_number: print("Plz choose higher number") elif guess_number > random_number: print("Plz choose lower number") else: print(f"Player {i+1}, You correctly...

Guess the number GAME (Guess limit is 9) - You vs. Computer

import random rNum = random . randint ( 1 , 100 ) i = 0 while i < 10 :     gn = int ( input ( "We have chosen a number between 1 and 100. Guess what? " ))     i += 1     print ( "Total guess limit is 9" )     print ( f "Guess number { i } " )     print ( "Total guesses left are" , 9 - i )         if i == 9 :         print ( "You exhausted your guess limit. Game over!" )         break     if gn < rNum :         print ( "Suggestion: Choose higer number" )     if gn > rNum :         print ( "Suggestion: Choose lower number" )             if gn == rNum :         print ( f "You Won the game in { i } guesses!. Your number was { gn } " )         print ( f "Our chosen number was { rNum } " )         break

You vs. Computer Guess Game (with error handling and Save-into-file high score capability)

Image
Error handling syntax try: except: import random rNum = random . randint ( 1 , 100 ) guesses = 0 while True :     try :         gn = int ( input ( "We have chosen a number between 1 and 100. Guess what? " ))         guesses += 1         if gn < rNum :                 print ( "Hint: Choose a higer number" )         if gn > rNum :                 print ( "Hint: Choose a lower number" )         if gn == rNum :                 print ( f "You guessed it right. Your number was { gn } " )                 print ( f "Our chosen number was { rNum } " )                 print ( f "You geussed it right in { guesses } guesses" )               ...

Guessing Game - Between You and Computer

 Guess the number?  import random rNum = random . randint ( 1 , 100 ) while True :     gn = int ( input ( "We have chosen a number between 1 and 100. Guess what? " ))     if gn < rNum :         print ( "Choose higer number" )     if gn > rNum :         print ( "Choose lower number" )     if gn == rNum :         print ( f "You guessed it right. Your number was { gn } " )         print ( f "Our chosen number was { rNum } " )         break