lundi 2 avril 2018

Changing random number in python

import random

def guess_number_game():

number = randbelow(1, 101)

points = 0

print('You already have ' + str(points) + ' point(s)')

playing = True

while playing:

    print(number)

    guess = int(input('Guess the number between 1 and 100: '))

    if guess > number:
        print('lower')
    elif guess < number:
        print('Higher')
    else:
        print('You got it, Good job!!')
        playing = False
        points += 1
        play_again = True

    while play_again:

        again = input('Do you want to play again type yes/no: ')

        if again == 'yes':
            playing = True
            play_again = False
        elif again == 'no':
            play_again = False
        else:
            print('please type yes or no')
print('Now you have ' + str(points) + ' point(s)')




guess_number_game()

i just started to learn python and i made this simple number guessing game, but if you try to play again you get the same number.

e.g. the number is 78 and you guessed it but you want to play again so you say you want to play again the number is still 78.

so how do i make it so that the number changes everytime someone plays the game




Aucun commentaire:

Enregistrer un commentaire