File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import random
2+
3+ def play_game ():
4+ print ("=== Higher or Lower Number Game ===" )
5+ print ("The goal is simple: guess if the next number will be Higher (H) or Lower (L)." )
6+ print ("If you guess wrong, the game ends.\n " )
7+
8+ score = 0
9+ current_number = random .randint (1 , 100 )
10+
11+ while True :
12+ print (f"Current number: { current_number } " )
13+ choice = input ("Will the next number be (H)igher or (L)ower? " ).strip ().lower ()
14+
15+ if choice not in ["h" , "l" ]:
16+ print ("Invalid input. Type 'H' or 'L'.\n " )
17+ continue
18+
19+ next_number = random .randint (1 , 100 )
20+ print (f"Next number: { next_number } " )
21+
22+ if (choice == "h" and next_number > current_number ) or \
23+ (choice == "l" and next_number < current_number ):
24+ score += 1
25+ print (f"Correct! Score: { score } \n " )
26+ current_number = next_number
27+ else :
28+ print ("Incorrect guess. Game Over." )
29+ print (f"Your final score was: { score } " )
30+ break
31+
32+
33+ if __name__ == "__main__" :
34+ play_game ()
Original file line number Diff line number Diff line change 1+ # Higher or Lower Number Game
2+
3+ This is a simple console-based ** Higher or Lower** game written in Python.
4+
5+ The game generates a random number between 1 and 100.
6+ Your task is to guess whether the next number will be ** higher** or ** lower** than the current one.
7+
8+ If your guess is correct, your score increases and the game continues.
9+ If your guess is wrong, the game ends and your final score is displayed.
10+
11+ ---
12+
13+ ## How to Run
14+
15+ 1 . Make sure you have ** Python 3** installed.
16+
17+ 2 . Open a terminal and navigate to the folder where the script is located:
18+ ``` bash
19+ cd higher_lower_game
20+ # # Made By Facundo Ceballos (Laker109:https://github.com/laker109)
You can’t perform that action at this time.
0 commit comments