Python Code HS Question
Hey guys! Can anybody please help me? I need to make a program where the user asks a question and the program responds with “yes” “no” “maybe” and other random phrases, kind of like a fortune teller. I have imported random already and created a list with the possible outputs and a print function. I’m just curious, is there a way I can include “def (parameters): ” with code in this function? Like is there anything I could add to my program so I can use a function like this? Thank you for your time :)
from random import choices
def(parameters, parameterstwo):
list = parameterstwo
x = choices(list, weights=parameters)
print(x)
Yes.
@SimplyMiah
So what you can do is
Syntax:
from random import choices
choices syntax is
choices(list, optional weights=args, optional cum_weights = args)
go look up the random documentary too
ya, wdym?
I don't understand. what are you trying to do?
So adding parameters pretty straightforward assuming you already know how to do the part with random. So your basic program probably looks something like this currently:
or using a variable for the list like this:
Now if you want to use a parameter all you need to do is to pass a parameter instead of declaring a variable like this: