Last active
May 28, 2022 12:45
-
-
Save jakariyaa/2475a078665dc5ef5fc5005ac7c98083 to your computer and use it in GitHub Desktop.
Just a silly guessing game made on a boring day while practicing Python after a while!
This file contains hidden or 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
# Guessing Game Made Harder To Guess | |
import random | |
while True: | |
random_num = random.randint(1, 50) | |
random_indecrement = random.randint(7, 25) | |
indecrement_history = [] | |
guess_count = 0 | |
print("\n How to play? The rules are simple: you have to guess the number correctly." | |
"\n If you guess higher! The number will get incremented according to the shown value" | |
"\n and decremented for guessing lower! The random number will be choosen from 1 to 50" | |
"\n Pretty simple game! eh? Guess the nummber in 5 try! Good luck \n") | |
while guess_count < 5: | |
indecrement_history.append(random_num) | |
#print(f"\n Guess Number : {random_num} \n [In/De]crement Value : {random_indecrement} " | |
# f"\n Guess Count : {guess_count} \n [In/De]crement History : {indecrement_history} \n") | |
if guess_count > 0: print(f" [In/De]crement Value : {random_indecrement} \n") | |
guess = input("Guess the number : ") | |
try: | |
guess = int(guess) | |
except ValueError: | |
if guess.lower() == "exit": | |
print("\n Thanks for trying out the game! Bye Bye Geek! \n") | |
else: | |
print("\nIt seems you are bored of this boring game! \n" | |
"Exiting the game Unconditionally! \n") | |
exit() | |
guess_count = guess_count + 1 | |
if guess == random_num: | |
print("\nCongrats! You've guessed the number correctly!") | |
wrong_guess_count = guess_count - 1 | |
if wrong_guess_count > 0: | |
print(f"You've guessed wrong for {wrong_guess_count} time[s].") | |
elif guess_count == 1: | |
print("Hurray! You've guessed correctly at first try!") | |
print(f"The guess number history : {indecrement_history}") | |
response = input("Wanna play again? (y/n) : ") | |
if response.lower() == "y": | |
break | |
else: | |
print("\n Thanks for playing! Bye Bye Geek! \n") | |
exit() | |
elif guess > random_num: | |
if guess == 99999: | |
print(f"The number is {random_num} \n" | |
f"The guess number history : {indecrement_history} \n" | |
"Restrating the game! \n") | |
break | |
elif guess > random_num + 7: | |
if guess > random_num + 35: | |
print(" Guessed Too high") | |
else: | |
print(" Guessed High") | |
else: | |
print(" Guessed Bit High") | |
random_num = random_num + random_indecrement | |
print(" Guess Number Incremented!") | |
elif guess < random_num: | |
if guess < random_num - 7: | |
if guess < random_num - 35: | |
print(" Guessed Too low") | |
else: | |
print(" Guessed Low") | |
else: | |
print(" Guessed Bit Low") | |
random_num = random_num - random_indecrement | |
print(" Guess Number Decremented!") | |
if guess_count > 4: | |
print("\nYou must guess the number in 5 try! Try better next time! \n" | |
f"The guess number were : {indecrement_history} \n" | |
"Restarting The Game.\n") | |
continue | |
### DO NOT COPY THE BELOW PART AS IT IS NOT NECESSARY TO RUN THE GAME ### | |
''' | |
Never mind! Just a silly guessing game made on | |
a boring day while practicing Python after a while! | |
What is special anyway? yeah ikr you'll ask that. | |
Nothing much. It just changes the number if you guess it incorrectly. | |
Increases the number based on the 'indecrement' value if you guess the number higher | |
while Decreases it if you guess it lower than the number. | |
Feeling unlucky? type '99999' and see. | |
Remove the 2 '#' from 12th and 13th line to see the how the game works live in action. | |
Please have a close look at the code to understand it better. | |
It isn't that hard though! ;)) | |
######################### | |
# CHANGELOG 28-5-22 # | |
######################### | |
+ Improved the code | |
- Removed slang words | |
+ Added [In/De]crement Value visibilty | |
to make the game actually playable | |
+ Shows if Incrementing or Decrementing | |
for better understanding | |
- Guess count reduced to 5! You must | |
guess the number in 5 try | |
+ Added a simple note on how to | |
play the game at the start | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment