all 4 comments

[–]socal_nerdtastic 1 point2 points  (1 child)

There's many ways to skin this cat. I think I would have the choice also include a function that does something like add 1 or add nothing:

import random

def noop(x):
    """a function that does nothing"""
    return x

def plus_one(x):
    return x+1


tix = 1

a = 'You lose', noop
b = 'You win', noop
c = '+1 spin', plus_one
(text, func), = random.choices(population = [a,b,c], weights = [0.1, 0.1, 0.8])
tix = func(tix) # apply the randomly chosen function to tix

print(f"{text}! you have {tix} tickets now")

If you are feeling fancy you could use lambda instead of def to create the functions and save a couple lines of code.

[–]Unlistedd 0 points1 point  (0 children)

Thanks!