Weird execution of my program: :Console Reset

Solved
KikouillesUwU -  
 KikouillesUwU -

Good evening everyone,

I am a beginner in Python and I have an assignment that asks me to add a gift of your choice to the list. So it asks to add a gift in the console (either a value).

And when I run it, it only shows *** Remote process console reset ***.

Here is my program:

list_gift=['game console','a bike', 'books','money','a surprise'] prenom=['Patrick Bateman','Vladimir','Magicarp','Ruby Nikara','Ernest Khalimov'] import random def add_to_list(list_gift): return list_gift print('here is a gift:',random.randint(list_gift(0,len(list_gift)-1))) add_to_list(list_gift)

Thank you for your help X)

2 answers

jee pee Posted messages 31857 Registration date   Status Moderator Last intervention   9 971
 

Hello,

The return statement ends your function, so it never executes up to the print line. Your program does nothing. And you don't see the error in this line. To access a value in your list, you need to use the list[i] syntax. Finally, with the return, you don’t need to return the list passed as a parameter, as it is not modified. One use of return could be to return the chosen value from the list. I correct your syntax and propose two other uses of random for a random choice, depending on whether you want an index number or directly a value.

list_gift=['console de jeux','un vélo', 'des livres','de l’argent','une surprise'] prenom=['Patrick Bateman','Vladimir','Magicarp','Ruby Nikara','Ernest Khalimov'] import random def ajout_list(list_gift): print('here’s a gift:',list_gift[random.randint(0,len(list_gift)-1)]) print('here’s a gift:',list_gift[random.randrange(len(list_gift))]) print('here’s a gift:',random.choice(list_gift)) return ajout_list(list_gift)

Finally, I don’t quite see the connection between your program, which could be summarized as "choosing a gift" and the statement (is it complete?) "add a gift according to your wish to the list". In this latter case, I would have used an input to ask the user what gift they want to add, and this gift would come to complement list_gift.

PS: to display code, you should use the specialized icon <>, and specify the language, Python, for syntax highlighting.

1
KikouillesUwU
 

Oh yes, that's right, thank you very much!

Oh no, I didn't send the right statement ^^'

But it's good now, I understood (damn return) x)

Thanks again and have a good day

0