B
B
B0w12022-04-20 22:32:40
Python
B0w1, 2022-04-20 22:32:40

Why doesn't a simple python game work?

I launch the game through the console and nothing, even errors does not give out.

def game():
  number = random.randint(0, 1000)
  tries = 1
  done = False

  while not done:
    guess = input('Введите число: ')
    if guess.isdigit():
      guess = int(guess)

      if guess == number:
        done = True
        print('Ты победил! Я загадал {guess}. Ты использовал {tries} попыток.')

      else:
        tries += 1
        if guess > number:
          print('Загаданное число меньше!')
        else:
          print('Загаданное число больше!')
    else:
      print('Это не число от 1 до 1000!')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sswwssww, 2022-04-20
@alex22122

In order for the function to run, you need to call it:

def game():
  number = random.randint(0, 1000)
  tries = 1
  done = False

  while not done:
    guess = input('Введите число: ')
    if guess.isdigit():
      guess = int(guess)

      if guess == number:
        done = True
        print('Ты победил! Я загадал {guess}. Ты использовал {tries} попыток.')

      else:
        tries += 1
        if guess > number:
          print('Загаданное число меньше!')
        else:
          print('Загаданное число больше!')
    else:
      print('Это не число от 1 до 1000!')


game()

M
Mikhail Krostelev, 2022-04-20
@twistfire92

write at the end

if __name__=='__main__':
    game()

or
game()
you just declared the function, but did
n't call it. No values ​​will be inserted into the message when you win. It's not an f-string. Put an f in front of the quotation marks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question