Untitled
unknown
python
2 years ago
5.4 kB
1
Indexable
Never
import random from time import sleep from os import system score = [] def getScore(): return score[0] def addScore(amt): global score # needed to change score globally if len(score) > 0: score[0] += amt else: score.append(amt) def startGame(difficulty): # Difficulty check if difficulty == 1: num = random.randint(1, 3) guess = int(input("Enter your guess: ")) attemps = 0 while True: if guess == num: print("Wow you guessed correctly! here is a cookie 🍪") if attemps == 1: addScore(3) elif attemps < 3: addScore(2) elif attemps >= 3: addScore(1) sleep(1) break elif guess > num: print("Almost there guess lower👇!") guess = int(input("Enter your guess: ")) attemps += 1 elif guess < num: print("Almost there guess higher👆!") guess = int(input("Enter your guess: ")) attemps += 1 elif difficulty == 2: num = random.randint(1, 6) guess = int(input("Enter your guess: ")) attemps = 0 while True: if guess == num: print("Wow you guessed correctly! here is a cookie 🍪") if attemps == 1: addScore(6) elif attemps < 4: addScore(4) elif attemps > 4: addScore(2) sleep(1) break elif guess > num: print("Almost there guess lower👇!") guess = int(input("Enter your guess: ")) attemps += 1 elif guess < num: print("Almost there guess higher👆!") guess = int(input("Enter your guess: ")) attemps += 1 elif difficulty == 3: num = random.randint(1, 10) guess = int(input("Enter your guess: ")) attemps = 0 while True: if guess == num: print("Wow you guessed correctly! here is a cookie 🍪") if attemps == 1: addScore(10) elif attemps < 5: addScore(6) elif attemps > 5: addScore(3) sleep(1) break elif guess > num: print("Almost there guess lower👇!") guess = int(input("Enter your guess: ")) attemps += 1 elif guess < num: print("Almost there guess higher👆!") guess = int(input("Enter your guess: ")) attemps += 1 elif difficulty == 4: num = random.randint(1, 13) guess = int(input("Enter your guess: ")) attemps = 0 while True: if guess == num: print("Wow you guessed correctly! here is a cookie 🍪") if attemps == 1: addScore(13) elif attemps < 6: addScore(7) elif attemps > 6: addScore(4) sleep(1) break elif guess > num: print("Almost there guess lower👇!") guess = int(input("Enter your guess: ")) attemps += 1 elif guess < num: print("Almost there guess higher👆!") guess = int(input("Enter your guess: ")) attemps += 1 elif difficulty == 5: num = random.randint(1, 15) print("You found a hidden difficulty good luck!") guess = int(input("Enter your guess: ")) attemps = 0 while True: if guess == num: print("Wow you guessed correctly! here is a cookie 🍪") if attemps == 1: addScore(15) elif attemps < 7: addScore(8) elif attemps > 7: addScore(5) sleep(1) break elif guess > num: print("Almost there guess lower👇!") guess = int(input("Enter your guess: ")) attemps += 1 elif guess < num: print("Almost there guess higher👆!") guess = int(input("Enter your guess: ")) attemps += 1 print("Please choose a difficulty(1/2/3/4/5)") print("1. Easy") print("2. Medium") print("3. Hard") print("4. Insane") try: while True: diff = int(input("Difficulty: ")) if len(score) > 0: print("Current high score", getScore()) else: print("You have no current high scores") startGame(diff) flag = input("Would you like to play again?(y/n) ") if flag.lower() == "n": break else: system("cls") except ValueError: print("Invalid difficulty ❌") input("Press any key to exit...")