'I would like to simulate a simple game using conditional probability in R or Python

Imagine I have 2 teams of 2 players. For each player, there exist two probability statistics-- call one an attempt % and another a score %.

To calculate the odds of a player scoring, I would multiply the attempt % by the scoring %. How could I create a program that simulates turns from each team that continues until a player scores 15 times?



Solution 1:[1]

recursion would be one way to do it:

do_stuff <- function(payload, turn = 1, max_turns = 15){
    if(turn >= max_turns) return(payload)
    payload  <- recalculate_payload(payload) ## desired recalculations here
    turn = turn + 1
    do_stuff(payload, turn, max_turns)
}

do_stuff(payload = pi) ## instead of Pi, could be a `data.frame` or other 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1