wish = True
, а конец кода стал таким: while wish == True:
a = input ('To start new game enter "s"\nTo exit enter "x"\n')
if a == 's':
game()
elif a == 'x':
wish = False
sys.exit ('Closing...')
running = True
в саму функцию не включал. Сейчас ещё раз попробовал, получилось что-то такое: import random
import sys
def game():
running = True
number = random.randint (1, 5)
print ('Guess the number from 1 to 5 to WIN')
print ('To exit enter "0"\n')
while running:
guess = int(input('Enter a number\n'))
if guess == number:
print ('YOU WIN!!!')
running = False
elif guess > number:
print ('Your number is bigger')
print ('Try again\n')
elif guess == 0:
sys.exit ('Closing...')
else:
print ('Your number is less')
print ('Try again\n')
game()
a = input ('To start new game enter "s"\nTo exit enter "x"\n')
if a == 's':
game()
elif a == 'x':
sys.exit ('Closing...')