Dec-21-2021, 01:57 PM
Hi guys,
I have this assignment that I've been working on but my head has been
. Was wondering if I could get some help solving it.
Thx in advance.
I basically have to create/define a function that:
1. checks if sum < 21, then print a str
2. checks if sum > 21 and if it is, check if there are 1 or more 11's. If there are then reduce the total sum by 10. Then check the list again for 11's and if there are any reduce the sum by 10 again.
3. if sum is still > 21 and there are no more reductions possible then str
4. if sum == 21 and there's only one 11 and one 10 in the list then str
With the exception of 3 hands that I can't get to continue to reduce, everything else is peachy.
Ok, here's what I have so far:
And this is the output:
The value of your hand is 16
Winner Winner Chicken Dinner!
31
22
Busted!
Busted!
Winner Winner Chicken Dinner!
Once again...Thx
Cheers,
54
The value of your hand is 21
I have this assignment that I've been working on but my head has been

Thx in advance.
I basically have to create/define a function that:
1. checks if sum < 21, then print a str
2. checks if sum > 21 and if it is, check if there are 1 or more 11's. If there are then reduce the total sum by 10. Then check the list again for 11's and if there are any reduce the sum by 10 again.
3. if sum is still > 21 and there are no more reductions possible then str
4. if sum == 21 and there's only one 11 and one 10 in the list then str
With the exception of 3 hands that I can't get to continue to reduce, everything else is peachy.
Ok, here's what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
def get_hand_value( * args): if sum (args) < = 21 and args.count( 11 ) = = 0 : return "The value of your hand is {0}" . format ( sum (args)) elif sum (args) > 21 and args.count( 11 ) = = 1 or args.count( 11 ) > 1 : return ( sum (args) - 10 ) # elif elif sum (args) > 21 and args.count( 11 ) = = 0 : return "Busted!" else : if sum (args) = = 21 and args.count( 11 ) = = 1 and args.count( 10 ) = = 1 : 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) |
The value of your hand is 16
Winner Winner Chicken Dinner!
31
22
Busted!
Busted!
Winner Winner Chicken Dinner!
Once again...Thx
Cheers,
54
The value of your hand is 21