0

Rare Chance

I want to create a simple program where when i type "roll" it will 70% generate a R text, 20% SR text, and 10% SSR text, much like lootbox system in videogame. Anyone know how to code it? Not using the if numb < 90 print R if possible...

19th Aug 2019, 7:49 AM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar
10 Respostas
+ 2
Random has a function called choices where it chooses a value from an iterator (like a list) based on preassigned weights. See below https://code.sololearn.com/cDCpEz2kxYdD/?ref=app
22nd Aug 2019, 5:21 AM
Trigger
Trigger - avatar
19th Aug 2019, 7:56 AM
Trigger
Trigger - avatar
+ 2
'*' is an unpacking operator. When used before iterators (lists) it will "unpack" them. Really handy operator to keep in mind
22nd Aug 2019, 6:30 AM
Trigger
Trigger - avatar
22nd Aug 2019, 6:33 AM
Trigger
Trigger - avatar
+ 1
Show your attempt? The random module in python will be able to help you👍🏼
19th Aug 2019, 7:51 AM
Trigger
Trigger - avatar
+ 1
Ok thanks for info! I guess i should spend more time studying python
22nd Aug 2019, 6:32 AM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar
0
My attempt almost same as yours, any other code?
21st Aug 2019, 1:15 PM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar
0
What do you mean by other code?
21st Aug 2019, 1:49 PM
Trigger
Trigger - avatar
0
Not using those x > z thing, if possible...
22nd Aug 2019, 3:24 AM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar
0
Yes this is! By the way can you explain why when we print(choices(...)) the output had a [] and ' Then when we write print(*choices(...)) it will show normal text
22nd Aug 2019, 6:27 AM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar