I want explaination of this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

I want explaination of this code

import random def deal_card(): cards=[11,2,3,4,5,6,7,8,9,10,10,10,10] card=random.choice(cards) return card """"Retruns a random cards""""" def calculate_score(cards): if 11 in sum(cards)==21 and len(cards)==2: return 0 if 11 in cards and sum(cards)>21: cards.remove(11) cards.append(1) return cards user_cards=[] computer_cards=[] is_game_over=False for _ in range(2): new_card=deal_card() user_cards.append(new_card) computer_cards.append(deal_card) while not is_game_over: user_score=calculate_score(user_cards) computer_score=calculate_score(computer_cards) print(f" Your cards:{user_cards}") print(f"Computer's First card:{computer_cards}") if user_score==0 or computer_score==0 or user_score>21: is_game_over=True else: user_should_deal=input("Type 'y ' to get another card, type 'n' to pass: ") if user_should_deal=="y":

21st Nov 2021, 10:31 AM
Abhishek
Abhishek - avatar
1 Answer
+ 7
Hello Abhishek Bairwa, Your code got truncated because it's too big to fit in the Description. I suggest you to save that as new code bit, and replace the truncated raw text code with the code bit link, for completeness reasons ... Here's how https://www.sololearn.com/post/75089/?ref=app
21st Nov 2021, 10:47 AM
Ipang