For this program you will build a simple dice game called Pig. In this version of Pig, two players alternate turns. Players each begin the game with a score of 0. During a turn a player will roll a six-sided die one or more times, summing up the resulting rolls. At the end of the player's turn the sum for that turn is added to the player's total game score If at any time a player rolls a 1, the player's turn immediately ends and he/she earns O points for that turn (i.e. nothing is added to the player's total game score). This is called "pig". After every roll that isn't a 1, the player may choose to either end the turn, adding the sum from the current turn to his/her total game score, or roll again in an attempt to increase the sum. The first player to 50 points wins the game
Details
Open a text editor and create a new file called pig.py. In the file
Write a function called print_scores that has four parameters - these hold, in this order, the name of the first player (a string), his/her score (an int), the second player's name (a string), and score (an int).
The function will
Print the following message, using the current parameter values for the player names and scores (NOT necessarily Ziggy, 18, Elmer, and 23) -SCORES Ziggy:18 Elmer 23--
Print an empty line before this line
There is a single tab between SCORES and the name of player 1 .
There is a single tab between player 1's score and player 2's name .
Every other gap is a single space

Answers

Answer 1

Answer:

In Python:

import random

p1name = input("Player 1: "); p2name = input("Player 2: ")

p1score = 0; p2score = 0

playerTurn = 1

print(p1name+" starts the game")

roll = True

while(roll):

   if playerTurn == 1:

       p1 = random.randint(1,6)

       print(p1name+"'s roll: "+str(p1))

       if p1 == 1:

           playerTurn = 2

           roll = True

       else:

           p1score+=p1

           another = input("Another Roll (y/n): ")

           if another == "y" or another == "Y":

               roll = True

           else:

               playerTurn = 2

               roll = True

   else:

       p2 = random.randint(1,6)

       print(p2name+"'s roll: "+str(p2))

       if p2 == 1:

           playerTurn = 1

           roll = True

       else:

           p2score+=p2

           another = input("Another Roll (y/n): ")

           if another == "y" or another == "Y":

               roll = True

           else:

               playerTurn = 1

               roll = True

   if p1score >= 50 or p2score >= 50:

       roll = False

print(p1name+":\t"+str(p1score)+"\t"+p2name+":\t"+str(p2score))

Explanation:

Note that the dice rolling is simulated using random number whose interval is between 1 and 6

This imports the random module

import random

This line gets the name of both players

p1name = input("Player 1: "); p2name = input("Player 2: ")

This line initializes the scores of both players to 0

p1score = 0; p2score = 0

This sets the first play to player 1

playerTurn = 1

This prints the name of player 1 to begin the game

print(p1name+" starts the game")

This boolean variable roll is set to True.

roll = True

Until roll is updated to False, the following while loop will be repeated

while(roll):

If player turn is 1

   if playerTurn == 1:

This rolls the dice

       p1 = random.randint(1,6)

This prints the outcome of the roll

       print(p1name+"'s roll: "+str(p1))

If the outcome is 1, the turn is passed to player 2

       if p1 == 1:

           playerTurn = 2

           roll = True

If otherwise

       else:

Player 1 score is updated

           p1score+=p1

This asks if player 1 will take another turn

           another = input("Another Roll (y/n): ")

If yes, the player takes a turn. The turn is passed to player 2, if otherwise

           if another == "y" or another == "Y":

               roll = True

           else:

               playerTurn = 2

               roll = True

If player turn is 2

   else:

This rolls the dice

       p2 = random.randint(1,6)

This prints the outcome of the roll

       print(p2name+"'s roll: "+str(p2))

If the outcome is 1, the turn is passed to player 1

       if p2 == 1:

           playerTurn = 1

           roll = True

If otherwise

       else:

Player 2 score is updated

           p2score+=p2

This asks if player 2 will take another turn

           another = input("Another Roll (y/n): ")

If yes, the player takes a turn. The turn is passed to player 1, if otherwise

           if another == "y" or another == "Y":

               roll = True

           else:

               playerTurn = 1

               roll = True

If either of both players has scored 50 or above

   if p1score >= 50 or p2score >= 50:

roll is updated to False i.e. the loop ends

       roll = False

This prints the name and scores of each player

print(p1name+":\t"+str(p1score)+"\t"+p2name+":\t"+str(p2score))


Related Questions

Charging current being returned to the battery is always measured in DC Amps. true or false

Answers

Answer:Charging current being returned to the battery is always measured in DC Amps. Electrical energy will always flow from an area of low potential to an area of high potential. ... One volt is the pressure required to force one amp of current through a circuit that has 1 Ohm of resistance.

Explanation:

A service specialist from your company calls you from a customer's site. He is attempting to install an upgrade to the software, but it will not install; instead, it he receives messages stating that he cannot install the program until all non-core services are stopped. You cannot remotely access the machine, but the representative tells you that there are only four processes running, and their PID numbers are 1, 10, 100, and 1000. With no further information available, which command would you recommend the representative run?

Answers

Answer:

kill 1000

Explanation:

Select the correct answer.
David gets a new job as a manager with a multinational company. On the first day, he realizes that his team consists of several members from diverse cultural backgrounds. What strategies might David use to promote an appreciation of diversity in his team?
A.
Promote inclusion, where he can encourage members to contribute in discussions.
B.
Create task groups with members of the same culture working together.
C.
Allow members time to adjust to the primary culture of the organization.
D.
Provide training on the primary culture to minority groups only if there are complaints against them.

Answers

C because it’s the smartest thing to do and let the other people get used to each other

Answer:

A.

Explanation:

If we were to go with B, then it would exclude others from different cultures, doing what he is trying to.

If we went with C, then they wouldn't get along very well, because no one likes to be forced into a different religion.

If we went with D, he wants an appreciation, so training some people to change religions if there are complaints, is not going to cut it. Therefore, we have A. Which I do not need to explain.

PLEASE HELP How have phones made us spoiled? How have phones made us unhappy?

Answers

phones have made us spoiled because we have everything at our fingertips. we get what we want when we see something online and we want to get it all we do is ask and most of us receive. phone have made us unhappy mentally and physically because we see how other people have it like richer for instance and we want that and we get sad about weird things because of what we see like other peoples body’s how skinny someone is and how fat someone is it makes us sad because we just want to be like them.

How many different values can a bit have?
16
2
4.
8

Answers

Answer:

A bit can only have 2 values

In cell 14, calculate


the profit by


subtracting the


donation from the


streaming revenues.

Answers

Answer:

See Explanation

Explanation:

The question is incomplete as the cells that contains donation and streaming revenues are not given

So, I will make the following assumption:

H4 = Donations

G4 =  Streaming Revenues

So, the profit will be:

Enter the following formula in cell I4

=(G4 - H4)

To get the actual solution in your case, replace G4 and H4 with the proper cell names

As the network engineer, you are asked to design a plan for an IP subnet that calls for 25 subnets. The largest subnet needs a minimum of 750 hosts. Management requires that a single mask must be used throughout the Class B network. Which of the following lists a private IP network and mask that would meet the requirements?

a. 172.16.0.0 / 255.255.192.0
b. 172.16.0.0 / 255.255.224.0
c. 172.16.0.0 / 255.255.248.0
d. 172.16.0.0 / 255.255.254.0

Answers

Answer:

c. 172.16.0.0 / 255.255.248.0

Explanation:

The address will be 172.16.0.0 while the netmask will be 255.255.248.0.

Thus, option C is correct.

A realtor is studying housing values in the suburbs of Minneapolis and has given you a dataset with the following attributes: crime rate in the neighborhood, proximity to Mississippi river, number of rooms per dwelling, age of unit, distance to Minneapolis and Saint Paul Downtown, distance to shopping malls. The target variable is the cost of the house (with values high and low). Given this scenario, indicate the choice of classifier for each of the following questions and give a brief explanation.
a) If the realtor wants a model that not only performs well but is also easy to interpret, which one would you choose between SVM, Decision Trees and kNN?
b) If you had to choose between RIPPER and Decision Trees, which one would you prefer for a classification problem where there are missing values in the training and test data?
c) If you had to choose between RIPPER and KNN, which one would you prefer if it is known that there are very few houses that have high cost?

Answers

Answer:

a. decision trees

b. decision trees

c. rippers

Explanation:

a) I will choose Decision trees because these can be better interpreted compared to these other two KNN and SVM. using Decision tress gives us a better explanation than the other 2 models in this question.

b)  In a classification problem with missing values, Decision trees are better off rippers since Rippers avoid the missing values.

c) Ripper are when we know some are high cost houses.

Write a function called 'game_of_eights()' that accepts a list of numbers as an argument and then returns 'True' if two consecutive eights are found in the list. For example: [2,3,8,8,9] -> True. The main() function will accept a list of numbers separated by commas from the user and send it to the game_of_eights() function. Within the game_of_eights() function, you will provide logic such that: the function returns True if consecutive eights (8) are found in the list; returns False otherwise. the function can handle the edge case where the last element of the list is an 8 without crashing. the function prints out an error message saying 'Error. Please enter only integers.' if the list is found to contain any non-numeric characters. Note that it only prints the error message in such cases, not 'True' or 'False'. Examples: Enter elements of list separated by commas: 2,3,8,8,5 True Enter elements of list separated by commas: 3,4,5,8 False Enter elements of list separated by commas: 2,3,5,8,8,u Error. Please enter only integers.

Answers

Answer:

In Python:

def main():

   n = int(input("List items: "))

   mylist = []

   for i in range(n):

       listitem = input(", ")

       if listitem.isdecimal() == True:

           mylist.append(int(listitem))

       else:

           mylist.append(listitem)

   print(game_of_eights(mylist))

def game_of_eights(mylist):

   retVal = "False"

   intOnly = True

   for i in range(len(mylist)):

       if isinstance(mylist[i],int) == False:

           intOnly=False

           retVal = "Please, enter only integers"

       if(intOnly == True):

           for i in range(len(mylist)-1):

               if mylist[i] == 8 and mylist[i+1]==8:

                   retVal = "True"

                   break

   return retVal

if __name__ == "__main__":

   main()

Explanation:

The main begins here

def main():

This gets the number of list items from the user

   n = int(input("List items: "))

This declares an empty list

   mylist = []

This iterates through the number of list items

   for i in range(n):

This gets input for each list item, separated by comma

       listitem = input(", ")

Checks for string and integer input before inserting item into the list

       if listitem.isdecimal() == True:

           mylist.append(int(listitem))

       else:

           mylist.append(listitem)

This calls the game_of_eights function

   print(game_of_eights(mylist))

The game_of_eights function begins here

def game_of_eights(mylist):

This initializes the return value to false

   retVal = "False"

This initializes a boolean variable to true

   intOnly = True

This following iteration checks if the list contains integers only

   for i in range(len(mylist)):

If no, the boolean variable is set to false and the return value is set to "integer only"

       if isinstance(mylist[i],int) == False:

           intOnly=False

           retVal = "Please, enter only integers"

This is executed if the integer contains only integers

       if(intOnly == True):

Iterate through the list

           for i in range(len(mylist)-1):

If consecutive 8's is found, update the return variable to True

               if mylist[i] == 8 and mylist[i+1]==8:

                   retVal = "True"

                   break

This returns either True, False or Integer only

   return retVal

This calls the main method

if __name__ == "__main__":

   main()

Other Questions
Environmental factors can influence the way genes are ________________. A sweater is 15% off. The regular price is $24. What is the price after the discount is taken off? Riley counted the number of balls on one layer of a box, 34. The box has 8 layers. How many balls can the box hold? In the biblical story of David and Goliath, a young boy takes down a giant using only a slingshot. Alluding to this story when describing a battle most likely implies that can someone please answer this HELP ASAP!!!Profit is the difference between revenue and cost. The revenue, in dollars, of a company that manufactures cell phones, can be modeled by the polynomial 2x2 + 55x + 10. The cost, in dollars, of producing the cell phones can be modeled by 2x2 15x 40. The variable x represents the number of cell phones sold.What expression represents the profit, and what is the profit if 240 cell phones are sold?40x 30; $2,40040x 30; $9,57070x + 50; $16, 85070x + 50; $28,800 ILL GIVE 50 POINTS AND BRAINLIEST!!! ;) Is a triangle with side lengths of 5, 10, and 15 a right triangle? Explain 30 POINTS FOR JUST ONE QUESTION :) Oliver is trying to keep up with the current amount of money in his bank account he uses positive numbers to show his the positive and negative numbers to show his withdraw which expression best represents Oliver making 8 withdraws $25 AFTER THE RAIN How do the insects and animals seem to feel about the recent rain? 10. How did the Mongols gain power?a. They inherited power from the Romansb. Nomadic tribes were unified under the leadership of Ghengis KhanThey came out of the Indus River valley cultured. They were appointed by the Byzantine emperorc. Helppppppppppppppppp ".... to over spread and to possess the whole of the continent which Providence has given us for the development of the great experiment of liberty and federaltive development of self government entrusted to us. It is right such as that of the tree to the space of air and the earth suitable for the full expansion of its principle and destiny of growth."what is john o sullivan talking about Read the paragraph from the section "The Message Was Heard."3"Tonda McGrath agreed. She said that if the school had responded to their concernsquickly and respectfully, there would have been no need for a vote."Which word DOES NOT have the same meaning as "concerns" as used in the abovesentence?a) injuriesb) complaintsc) worriesd) frustrations Need help QUICKLYY According to this diagram, which line color denotes the universal common ancestor for all 3 domains of life? A. BlueB. RedC. TanD. Black BUT HOW DID THE GENOCIDE HAPPEN How do different authors use the same information to createopposing arguments? Can you help me please