Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Casino - Homework
#2
What you're missing is a loop to test for more than one eleven. Here's a suggestion:
def get_hand_value(*args):

	hand_total = sum (args)
	total_elevens = args.count (11)
	while total_elevens > 0 and hand_total > 21 :
		total_elevens -= 1
		hand_total -= 10
	if hand_total  < 21 :
		return "The value of your hand is {0}".format(hand_total)
	elif hand_total > 21 :
		return "Busted!"
	else:
		return "Winner Winner Chicken Dinner!"
#-----------------------------------------------------------------------------
 
# While testing the execution of your program, I will use the hands below:
hand_1 = get_hand_value(4,4,4,4)
hand_2 = get_hand_value(11,10)
hand_3 = get_hand_value(11,5,6,4,11,4)
hand_4 = get_hand_value(11,5,6,10)
hand_5 = get_hand_value(10,5,7)
hand_6 = get_hand_value(5,6,5,10)
hand_7 = get_hand_value(10,11)
hand_8 = get_hand_value(11,11,11,11,10,10)
hand_9 = get_hand_value(5,6,5,5)
 
print(hand_1)
print(hand_2)
print(hand_3)
print(hand_4)
print(hand_5)
print(hand_6)
print(hand_7)
print(hand_8)
print(hand_9)
Output:
The value of your hand is 16 Winner Winner Chicken Dinner! Winner Winner Chicken Dinner! Busted! Busted! Busted! Winner Winner Chicken Dinner! Busted! Winner Winner Chicken Dinner!
Men likes this post
Reply


Messages In This Thread
Casino - Homework - by Men - Dec-21-2021, 01:57 PM
RE: Casino - Homework - by BashBedlam - Dec-21-2021, 04:13 PM
RE: Casino - Homework - by Men - Dec-21-2021, 04:50 PM
RE: Casino - Homework - by deanhystad - Dec-21-2021, 05:33 PM
RE: Casino - Homework - by Men - Dec-22-2021, 04:24 PM
RE: Casino - Homework - by LoriBrown - Dec-15-2022, 05:28 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020