Q. Two friends decide who gets the last slice of a cake by flipping a coin five times. The first person to win three flips wins the cake. An input of 1 means player 1 wins a flip, and a 2 means player 2 wins a flip. Design an algorithm to determine who takes the cake?


Answer:-


Set player1 = 0
Set player2 = 0
For i in range (5):
      Input coin number
      If coin = 1 then
           Player1 += 1
      Elif coin = then
           Player2 += 1

If player1 > 2 then
    Player1 wins

Elif player2 > 2 then
    Player2 wins

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post