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) 
  • second , in addition to numbers, can contain letters, and you are trying to add it to the number of player_deck+=second - Dmitry Kozlov
  • 2
    The func function has no return value and the results of the function are not assigned to anything. - Lecron

1 answer 1

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.