Question: Using Python 3.6.4: 10.33 In the simple coin game you are given an initial number of coins and then, in every iteration of the game,

Using Python 3.6.4:

10.33 In the simple coin game you are given an initial number of coins and then, in every iteration of the game, you are required to get rid of a certain number of coins using one of the following rules. If n is the number of coins you have then: If n is divisible by 10, then you may give back 9 coins.

If n is even, then you may give back exactly n/2 1 coins.

If n is divisible by 3, then you may give back 7 coins.

If n is divisible by 4, then you may give back 6 coins.

If none of the rules can be applied, you lose. The goal of the game is to end up with exactly 8 coins.

Note that more than one rule may be applied for some values of n. If n is 20, for example, rule 1 could be applied to end up with 11 coins. Since no rule can be applied to 11 coins, you would lose the game. Alternatively, rule 4 could be applied to end up with 14 coins, and then rule 2 could be applied to end up with 8 coins and win the game. Implement a function coins() that takes as input the initial number of coins and returns True if there is some way to play the game and end up with 8 coins. The function should return False only if there is no way to win.

>>> coins(7)

False

>>> coins(8)

True >>> coins(20)

True

>>> coins(66)

False >>> coins(99)

True

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!