1
I’m solving a Python exercise that asks the user to give a guess, on what number the program got to pc
randomly.
from random import randint
tent = int(input('PALPITE:'))
pc = randint(0,4)
cont = 0
while tent != pc:
pc = randint(0,4)
tent = int(input('Você errou! o numero que o pc escoheu foi {}. Tente novamente '.format(pc)))
print('Parabens!Você acertou! o Número que o o computador escolheu foi {}.'.format(pc))
The code until it works, but when I hit the number it says it’s wrong. When I put the input
that’s inside the while
to be running before (instead of randomizing the number first) the result works.
I know this has to do with the sequential structure, but I thought if I used the randint
in the variable pc
within the while
would first give the same result.
Why does this happen? Does it have to do with the logical expression up there? It is mandatory that I have received the value of input
inside the variable first and then Python parses?
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero