0
I created this system to generate a random number but I cannot reset the generated number every time the user selects play again, what would be the easiest way to solve this?
import random
numero_aleatorio = random.randint(1, 101)
while True:
chute = int(input('chute o numero entre 1 e 100: '))
if chute > numero_aleatorio:
print('o numero é menor, tente de novo\n')
elif chute < numero_aleatorio:
print('o numero é maior, tente de novo\n')
elif chute == numero_aleatorio:
print("parabens, você acertou\n")
opcao = input('quer jogar mais uma vez?(s/n): ')
if opcao == 's':
continue
else:
break
Maybe it would generate the random number within your repeat loop.
– Woss
Just think: "when the user selects play again?" - It is when he type "s", so just generate another random number within the
if opcao == 's'
- in fact, thecontinue
within theif
seems unnecessary to me– hkotsubo