Interview Query

Simulating Coin Tosses

Start Timer

0:00:00

Upvote
1
Downvote
Save question
Mark as completed
View comments (6)
Next question

Write a function that takes an input as the number of tosses and a probability of heads and return a list of randomly generated results equal in length to the number of tosses. Each result represents the outcome of a coin toss, where ‘H’ represents heads and ’T’ represents tails.

Example 1:

Input:

tosses = 5
probability_of_heads = 0.6

Output:

coin_toss(tosses, probability_of_heads) -> ['H', 'T', 'H', 'H', 'T']

Example 2:

Input:

tosses = 3
probability_of_heads = 0.2

Output:

coin_toss(tosses, probability_of_heads) -> ['T', 'T', 'T']

The output may vary due to the randomness of coin tosses.

.
.
.
.
.


Comments

Loading comments