Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

How complex are smart contracts

Answered: 1 week ago