Witajcie,
To moje początki programowania i potrzebuje małej pomocy, ponieważ chcę zrozumieć.
Poniższy program losuje liczbę a następnie porównuje z tą podaną przez użytkownika. Ilość prób użytkownika jest ograniczona do wersji "hard" lub "easy" .
Niestety program generuje mi następujący błąd: "SyntaxError: invalid syntax (<string>, line 40)".
Zupełnie nie mogę wyłapać gdzie leży problem. Będę wdzięczny za wskazówkę.
#from logo import logo
import random
#Number Guessing Game Objectives:
EASY_LEVEL_TURNS = 10
HARD_LEVEL_TURNS = 5
def check_guess(guess, comp_number, turns):
if comp_number < guess:
print("Too high.")
return turns - 1
elif comp_number > guess:
print("Too low.")
return turns - 1
else:
print(f"You got it! The answer was {guess}.")
# Include two different difficulty levels (e.g., 10 guesses in easy mode, only 5 guesses in hard mode).
def difficulty():
level = input("Choose a difficulty. Type 'easy' or 'hard': ")
if level == "hard":
return HARD_LEVEL_TURNS
else:
return EASY_LEVEL_TURNS
def game():
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
comp_number = random.randit(1,100)
turns = difficulty()
guess = 0
while guess != comp_number:
print(f"You have {turns} attempts remaining to guess the number.")
guess = int(input("Make a guess: ")
turns = check_guess(guess, comp_number, turns)
if turns == 0:
print("You've run out of guesses, you lose.")
return
elif guess != comp_number:
print("Guess again.")
game()