samedi 21 décembre 2019

How do i get a random int with 2 variables?

im trying to build a little number guessing game. im trying to pass 2 variables into a random.randint function but can't get it to work. im trying to get the users input on what the lowest possible secret number and the highest possible secret number i gonna be in the particular game. and then take a random number between the two inputs

this is how my code looks.

 lower_limit_sn = int(input('Decide the lowest possible secret number: '))
print(f'{lower_limit_sn}')

upper_limit_sn = int(input('Decide the highest possible secret number: '))
print(f'{upper_limit_sn}')

secret_number = random.randint({lower_limit_sn}, {upper_limit_sn})

and this is the error i get:

Traceback (most recent call last):
  File PycharmProjects/HelloWorld/While_loops.py", line 26, in <module>
    secret_number = random.randint({lower_limit_sn}, {upper_limit_sn})
  File AppData\Local\Programs\Python\Python37-32\lib\random.py", line 222, in randint
    return self.randrange(a, b+1)
TypeError: unsupported operand type(s) for +: 'set' and 'int'



Aucun commentaire:

Enregistrer un commentaire