second = random.choice([2,3,4,5,6,7,8,9,10,'J','Q','K','A']) player_deck = random.choice([2,3,4,5,6,7,8,9,10,'J','Q','K','A']) def func(x): if x == 'J' or x == 'Q' or x == 'K': x = 10 elif x == 'A': x = 11 func(player_deck) func(second) player_deck+=second print(player_deck) |
1 answer
Instead
def func(x): if x == 'J' or x == 'Q' or x == 'K': x = 10 elif x == 'A': x = 11 which returns None , use
def func(x): if x in 'JQK': # ΡΠΎΡ-ΠΆΠ΅ ΡΠ°ΠΌΠΎΠ΅, Π½ΠΎ Π±ΠΎΠ»Π΅Π΅ ΠΠΈΡΠΎΠ½ΠΈΡΠ΅ΡΠΊΠΎΠ΅ x = 10 elif x == 'A': x = 11 return x This function returns the x you want to ΠΏΡΠΈΠΌΠ΅Π½ΠΈΡΡ , and so instead of
func(player_deck) func(second) use just
player_deck = func(player_deck) second = func(second) Then the variables player_deck and second will be integers and in the command
player_deck + =second there will be no error.
|
second, in addition to numbers, can contain letters, and you are trying to add it to the number ofplayer_deck+=second- Dmitry Kozlovfuncfunction has no return value and the results of the function are not assigned to anything. - Lecron