In: Computer Science
Write a Python program to simulate a very simple game of
21
•Greet the user.
•Deal the user a card and display the card with an appropriate
message.
•Deal the user another card and display the card
.•Ask the user if they would like a third card. If so, deal them
another card and display the value with an appropriate
message.
•Generate a random number between 10 and 21 representing the
dealer’s hand. Display this value with an appropriate
message.
•If the user’s total is greater than the dealer’s hand and the
user’s total is NOT greater than 21, the user wins, otherwise the
dealer wins. Display the player’s and the dealer’s totals along
with an appropriate message indicating who won.
code:-
_____
import random
sum=0;
print("WELCOME TO THE GAME OF 21\n");
d=random.randint(0,21);
print("HERE IS YOUR 1st CARD:-");
print(d);
sum=sum+d;
d=random.randint(0,21);
print("HERE IS YOUR 2nd CARD:-");
print(d);
sum=sum+d;
user = input("WANT A THIRD CARD THEN ENTER yes ELSE ENTER no:\n");
if user == "yes" :
d=random.randint(0,21)
sum=sum+d
print("\nHERE IS YOUR 3rd CARD:-")
print(d)
print("\n");
else:
print("\n");
deal=random.randint(10,21);
if sum>deal and sum<21:
print("USER WON\n");
else:
print("DEALER WON\n");
print("DEALERS HAND NUMBER:-");
print(deal);
print("USERS TOTAL NUMBER:-");
print(sum);
output
_____
PLEASE GIVE THE THUMBS UP,IF YOU THINK IT IS RIGHT.