Respuesta :
Program Vingt-et-un is a dice game
#import modules
import random
#define variables
playerName = ""
playerTotal = 0
houseTotal = 0
dice1 = 0
dice2 = 0
menuOption = 0
#display the menu
def displayMenu():
print("\nVingt-et-un Game Menu \n")
print("1. See the rules. \n")
print("2. Play Vingt-et-un. \n")
print("3. Quit. \n")
#get the name of the player
def getPlayerName():
global playerName
playerName = input("Please enter your Name: ")
#display the rules of the game
def showRules():
print("Vingt-et-un is a dice game where a person faces off against the computer (known as Blackjack in the USA) (house). The objective of the game is to score 21, or as close to it as you can without going over. The two players alternately toss two dice as many times as they like, summing up the results after each round. If a player's total exceeds 21, they bust and lose the round. After each player has had a turn, the game is won by the one whose total is closest to 21. The game is tied if both teams have a high total. When either one or both players are bust, the round is done and the game is ended. Both players decide to continue.")
#roll the dice
def rollDice():
global dice1
global dice2
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
print("Dice 1: " + str(dice1))
print("Dice 2: " + str(dice2))
#calculate the players total
def calculatePlayerTotal():
global playerTotal
global dice1
global dice2
playerTotal += dice1 + dice2
print("\nYour total is: " + str(playerTotal))
#calculate the house total
def calculateHouseTotal():
global houseTotal
global dice1
global dice2
houseTotal += dice1 + dice2
print("\nHouse total is: " + str(houseTotal))
#player turn
def playerTurn():
global playerTotal
while True:
playerChoice = input("\nDo you want to stay or roll? (s/r): ")
if playerChoice == "s":
print("\nYou chose to stay.")
break
elif playerChoice == "r":
if playerTotal >= 14:
rollDice()
calculatePlayerTotal()
else:
rollDice()
calculatePlayerTotal()
else:
print("\nPlease enter either s or r.")
#house turn
def houseTurn():
global houseTotal
while True:
if houseTotal >= 17:
print("\nHouse chose to stay.")
break
else:
rollDice()
calculateHouseTotal()
#print the winner
def printWinner():
global playerTotal
global houseTotal
if playerTotal > 21:
print("\n" + playerName + " is bust. House won!")
elif houseTotal > 21:
print("\nHouse is bust. " + playerName + " won!")
elif playerTotal == houseTotal:
print("\nIt's a tie.")
elif playerTotal > houseTotal:
print("\n" + playerName + " won!")
else:
print("\nHouse won!")
#main function
def main():
global menuOption
getPlayerName()
while menuOption != 3:
displayMenu()
menuOption = int(input("\nPlease select an option (1-3): "))
if menuOption == 1:
showRules()
elif menuOption == 2:
playerTurn()
What is program?
Program is a set of instructions that are followed by a computer to execute a task or perform a specific function. Programs are typically written using a programming language, composed of a set of instructions that a computer can understand and execute. Programs range from simple, single-line commands to complex and lengthy applications. Programs are essential for the operation of modern computers, as they provide the instructions that allow computers to perform useful tasks, such as running software applications, processing data, and connecting to the internet.
to learn more about program
https://brainly.com/question/28224061
#SPJ4