Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help correcting my def session code. error: The function 'session' does not call 'prompt' properly. Test 'session' with random seed 1234 and the following

Need help correcting my def session code.

error: The function 'session' does not call 'prompt' properly. Test 'session' with random seed 1234 and the following input: a, c, 3, A, b, 1, b, x, b, d, B, b, s. 

import random

import introcs

def payout(bet,score):

"""

Returns the winnings for a game of quasar.

Winnings are payout-bet.So winning your bet (on a score of 17) has a net of 0.

Parameter bet: the number of credits bet

Precondition: bet is an int > 0

Parameter score: the quasar score

Precondition: score is an int >= 0

"""

if score == 20:

return bet

elif score == 19:

return round(0.5*bet)

elif score == 18:

return round(0.25*bet)

elif score == 17:

return 0

elif score == 16:

return round(-0.5*bet)

elif score == 15:

return round(-0.75*bet)

# Everything else is a total loss

return -bet

def session(bet):

"""

Returns the payout after playing a single session of quasar.

The game starts by randomly choosing a number 1-8 and then displaying

Your score is X.

(where X is the number chosen). It then prompts the user with the following options:

Choose (a) 4-7, (b) 1-8, or (s)top:

If the user chooses 'a' or 'b', it picks a random number, adds it to the score,

and then displays the score again.If the user chooses 's' OR the new score is

20 or more, the session is over.

Once the session ends, if the user goes over 20, the function prints out

You busted.

However, if the user hits 20 exactly, the function prints out

Quasar!

Nothing extra is printed if the user is below 20.

It then prints out

You won X credits.

or

You lost X credits.

as appropriate, where X is the payout (if X is 0, this is considered a win). When

the session is done, the function returns the payout.

Parameter bet: the number of credits bet

Precondition: bet is an int > 0

"""

score = random.randint(1, 8)

print('Your score is ' + str(score) + '.')

control = True

while control:

response = input('Choose (a) 4-7, (b) 1-8, or (s)top: ')

if response == 'a':

score = score + random.randint(4, 7)

if score < 20:

print('Your score is ' + str(score) + '.')

else:

control = False

elif response == 'b':

score = score + random.randint(1, 8)

if score < 20:

print('Your score is ' + str(score) + '.')

else:

control = False

elif response == 's':

control = False

if score > 20:

print('You busted.')

elif score == 20:

print('Quasar!')

pay = payout(bet, score)

if pay >= 0:

print('You won ' + str(pay) + ' credits.')

else:

print('You lost ' + str(pay) + ' credits.')

return pay

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

Step: 3

blur-text-image

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

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions