#π Need Help about a Program
38 messages Β· Page 1 of 1 (latest)
@wispy island
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
are you familiar with randomness in python?
Yes
Like random module???
Yes
Ok, so there's a few ways you can do this
well, your percentages only add up to 90%, so what's the last 10 percent?
You can say like 9% for thrice and 1% for ten times
!e
import random
chances = []
chances.extend(['lose'] * 60)
chances.extend(['return'] * 10)
chances.extend(['double'] * 20)
chances.extend(['triple'] * 9)
chances.extend(['ten times'] * 1)
print(chances)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
['lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'lose', 'return', 'return', 'return', 'return', 'return', 'return', 'return', 'return', 'return', 'return', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'triple', 'triple', 'triple', 'triple', 'triple', 'triple', 'triple', 'triple', 'triple', 'ten times']
ok, so you can do something like this to populate a list of all available options
and if you use random.choice, the percentages are higher for options that appear more
the other way to do this is using weights
What does like 'lose' * 60 does it mean add lose 60 times to a list???
After this will you use
If chances=="lose"
Print("lose")
Something like this?
yes exactly
yes
Ohh thanks i didnt even knew about it
!e
import random
chances = ['lose', 'return', 'double', 'triple', 'ten times']
chance_weights = [60, 10, 20, 9, 1]
print(random.choices(chances, weights=chance_weights, k=1))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
['double']
the other option is using a weights list
But listen i am going to make it like you can play untill you want to quit by typing 'q' so repeating that again and again will extend the list every time or list get resets each time when the loop starts again??
||@strange shale ||
don't include the list creation as part of the loop
Ok got it
Thanks bye
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.