Answer the question
In order to leave comments, you need to log in
How to change the value of a variable during the execution of a loop?
I'm trying to make a randomizer, but I can't display the remaining number of attempts + I don't understand why it doesn't respond to entering the correct number
import random
print('Угадай число от 1 до 12')
trys = int(input('сколько попыток хочешь? '))
rand = random.randint(0, 12)
print(rand)
for i in range(0, trys):
dict = {1: trys - 1}
tr1 = dict[1]
pop = input('Угадай число ')
if pop == rand:
print()
print('Правильно, было загадано число ', rand, '!')
print()
elif pop != rand:
print('Не верно, попробуй ещё раз, осталось ', tr1, ' попыток')
if trys == 0:
print('Попытки закончились, попробуй снова')
break
Answer the question
In order to leave comments, you need to log in
pop == rnd, but rnd was nowhere before. Plus pop is a string. You need to cast pop to a numeric type.
In general, you should refactor this thing:
dict = {1: trys - 1}
tr1 = dict[1]
if trys == 0:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question