Created
July 11, 2022 23:56
-
-
Save AliAlmasi/16a8bde5adeca3e4ba02af2756a8e27c to your computer and use it in GitHub Desktop.
This file contains 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
from random import randint as rnd | |
from time import sleep as sl | |
def diff(): | |
global diff_lvl | |
diff_lvl = "" | |
print("Select difficulty (E = Easy / N = Normal / H = Hard)") | |
diff_select = input("Type and Enter: ") | |
diff_select.lower() | |
if diff_select == 'e': | |
diff_lvl = "easy" | |
elif diff_select == 'n': | |
diff_lvl = "normal" | |
elif diff_select == 'h': | |
diff_lvl = "hard" | |
else: | |
print("INVALID VALUE" + | |
"\n (E = Easy / N = Normal / H = Hard)") | |
diff() | |
print(f"You selected {diff_lvl} difficulty.") | |
def lvl(): | |
global guess_limit | |
global sec_num | |
rang = "" | |
if diff_lvl == "easy": | |
guess_limit = 3 | |
sec_num = rnd(1, 6) | |
rang = "1 to 6" | |
elif diff_lvl == "normal": | |
guess_limit = 4 | |
sec_num = rnd(1, 7) | |
rang = "1 to 7" | |
elif diff_lvl == "hard": | |
guess_limit = 6 | |
sec_num = rnd(1, 10) | |
rang = "1 to 10" | |
else: | |
print("ERROR: diff_lvl UNDEFINED") | |
quit() | |
print(f"You got '{guess_limit}' chances to guess the number."+ | |
f"\nThe number is from {rang}.") | |
def main(): | |
diff() | |
sl(1) | |
lvl() | |
sl(1.5) | |
guess_count = 0 | |
while guess_count < guess_limit: | |
guess = int(input("Guess: ")) | |
guess_count += 1 | |
if guess == sec_num: | |
print(f"You win! =D\nThe answer was {guess}.") | |
break | |
else: | |
print(f"Sorry, you failed. :(\nThe answer was {guess}.") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment