Question: Please Solve in Python If the player doesnt win money from all slot machines, the system will increase the players luck in the next turn

Please Solve in Python

If the player doesnt win money from all slot machines, the system will increase the players luck in the next turn according to the following rule:

luck = (

0.001 * loss in machine 1 +

0.002 * loss in machine 2 +

min(0.005 * abs(500 - loss in machine 3), 0.003 * loss in machine 3)

- 2

)

Here the total loss is always considered positive: If a slot machine gives you -100 profit, then you lost 100.

If the player gains money from any of the slot machine, luck is set to -2

Write a function that can warn your friend about his luck in the next turn. It takes the dictionary from the last question as the input and updates the dictionary with a new key/value pair, {'luck': X} (X is 'Lucky' if luck is positive, 'Try again' if luck is 0, and 'Unlucky' if luck is negative).

Input Output Explanation

{ '1': -2064, '2':-627, '3': -652 }

{ '1': -2064, '2':-627, '3':-652, 'luck': 'Lucky' }

Using the formula for luck:

0.001 * 2064 + 0.002 * 627 + min(0.005 * 152, 0.003 * 652) - 2 = 2.078

{ '1': -865, '2':-342, '3': 5 }

{ '1': -865, '2':-342, '3': 5, 'luck': 'Unlucky' }

Notice, that the third slot machine allowed your friend to win money, so according to the second rule luck is set to -2

doctests:

def luck_test(records): """ >>> case1 = {'1': -865, '2':-342, '3': 5} >>> luck_test(case1) {'1': -865, '2': -342, '3': 5, 'luck': 'Unlucky'} >>> case2 = {'1': -2064, '2': -627, '3': -652} >>> luck_test(case2) {'1': -2064, '2': -627, '3': -652, 'luck': 'Lucky'} >>> case3 = {'1': -463, '2': -389, '3': -307} >>> luck_test(case3) {'1': -463, '2': -389, '3': -307, 'luck': ' Lucky'} """

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!