How to make a number with reset Random when restarting the program in python?

Asked

Viewed 19 times

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
  • 2

    Maybe it would generate the random number within your repeat loop.

  • 1

    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, the continue within the if seems unnecessary to me

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.