0
Can a random.choice be made into a variable?
Can you do something like a = random.choice() and when you need to fill the parameters you can do something llike if b == 5 a = random.choice(c)
9 Respuestas
+ 3
random.choice is a function that returns what it chooses from the iterable.
So yes, you can store that choice and use it later.
+ 5
In case you don't want to use such a long word, this is also valid:
import random
a = random.choice
print(a([1, 7, 3]))
Instead of calling the function, we're just giving it another name. But if that is your goal, I'd recommend
from random import choice as a
print(a([1, 7, 3]))
+ 3
Yes you can, why dont you try try it in code playground ? its faster than waiting for someone to answer
+ 1
Fbia34
the method 'choice' from random, expects a sequence argument,
so if you do this:
a = random.choice()
you will get an error telling you that.
+ 1
Fbia34 The problem with your only code is not that you used random.choice wrongly, but you are missing one comma. here i corrected for you:
https://code.sololearn.com/cbU63AFo2OeZ/?ref=app
+ 1
Fbia34 Welcome😉
try code more
basketballgirl's 800 upvote game is by random.choice
you can do it too~
+ 1
╰☆☆ S͎p͎e͎a͎r͎y͎ ☆☆╮ that's actually what this question is for, it's just a variation instead of earth it's space
0
╰☆☆ S͎p͎e͎a͎r͎y͎ ☆☆╮ oh this isn't for the art gen (which I made for a friend who said it worked fine) but thanks lol I didn't catch that
0
Fbia34 heres mine from the halloween contest:
https://code.sololearn.com/c22kNFrS19ds/?ref=app
edit:
this is made for ur question.
Purrfect debug,
withit