Answer:
import random
is_stay = 'n'
y_fcard = random.randint(1, 11)
y_scard = random.randint(1, 11)
d_fcard = random.randint(1, 11)
d_scard = random.randint(1, 11)
you_score = y_fcard + y_scard
dealer_s = d_fcard + d_scard
print("Your score", you_score)
print("dealer's score", dealer_s)
while is_stay == 'n':
if you_score > 21:
break
you_score += random.randint(1, 11)
print("Your score", you_score)
is_stay = input("Do you want to stay y/n?: ")
if you_score > 21:
print("You lost")
quit()
while dealer_s <= 16:
dealer_s += random.randint(1, 11)
if dealer_s > 21:
print("The dealer lost")
quit()
if you_score > dealer_s:
print("You are the winner", "My score: ",you_score, "\nDealer's score: ", dealer_s)
else:
print("Sorry, you lost the game", "My score: ",you_score, "\nDealer's score: ", dealer_s)
Explanation:
The python program uses the random module's 'randint' to get a random integer number between 1 and 11, and adds the value to the user's score if the user decides to hit but compares the result with the dealer's if the user stays.