mercredi 7 décembre 2022

Randint() missing 1 required positional argument: 'b' . code works if I want to use specific numbers but not if i want to add randomness

import random


list_of_names = []
length_of_list = int(input("give the number of people in your secret santa. make it even"))
if length_of_list % 2 != 0:
    print("that is not even")
    exit()
else: 
    pass

for i in range(length_of_list):
    name = input("give a name")
    list_of_names.append(name)

print(list_of_names)


random_thing = random.randint(len(list_of_names))
print(list_of_names[random_thing],"will have to buy a present for",list_of_names[random_thing])

the error comes up for the last line (23) and i don't understand why. I am aware that the code is not finished yet but i do not understand as to why it is giving me this error

it works if for example i do list_of_names[0] and list_of_names[1] but when i try and add randomness to the question it doesn't like it.

At first i tried putting the random function in the last line in the [] but outputted the same problem




Aucun commentaire:

Enregistrer un commentaire