Question

Please help as it is very important task for me please write in Python code and...

Please help as it is very important task for me please write in Python code and divide this into function and write comments for it

1. Ask the player’s name and welcome them to the game using their name.
2. Ask the player what is par for this game (number between 3-5 inclusive)
3. Ask the player what the distance to the hole for this game is (whole number between 195 and 250 inclusive) 4. Show the game menu:
(I)nstructions
(P)lay golf (Q)uit
The user will enter the first letter of each option to choose it.
5. If the user chooses (I) then the following message is to be displayed, given the par and distance amounts obtained above.
This is a simple golf game in which each hole is 230m game away with par 5. You are able to choose from 3 clubs, the Driver, Iron or Putter. The Driver will hit around 100m, the Iron around 30m and the Putter around 10m. The putter is best used very close to the hole.
After the instructions are displayed the game menu will be presented again. 6. If the player chooses (Q) then the following message is to be displayed:
Farewell and thanks for playing <user name>.
7. After displaying the instructions, or playing a round of golf, the program is to return to the menu and loop until the user chooses to quit
8. If the user chooses (P) then a game of golf will begin as described below
Playing the game:
• The player is first notified of the distance to the hole, which was specified in step 3 above.
• For each swing, the player chooses a club and then the program generates the distance hit for each shot, updating the distance to the hole accordingly. After each swing the distance the ball travelled, and the distance remaining is displayed along with the current score using a message similar to the one below:
Your shot went 103m.
You are 127m from the hole, after 1 shot/s.
• The player has three clubs to choose from for each shot. Each club hits the ball a set average distance, but the actual distance randomly varies between 80% and 120% of the average. For the Driver you will need to generate a random number between 80 and 120 to do this.
• The clubs and their average distances are:
o Driver: 100m (actual distance will be a random number between 80 and 120) o Iron: 30m (actual distance will be a random number between 24 and 36) o Putter: 10m (see below for actual distance)
• When the ball is inside 10m and the putter is used, the shot will be between 80% and 120% of the distance to the hole, not the club’s average distance. The minimum distance the putter can hit is 1m (no 0m hits). All distances are whole numbers.
• The user will enter the first letter of a club to choose it (i.e. ‘I’ or ‘i’ for the Iron)
• If an invalid club is chosen, the player is asked to make a valid choice.
• The ball cannot be a negative distance to the hole. Whether it is in front of or behind the hole, it is still a positive distance to the hole. Python has an absolute value function that you can use to help you with this.
• Play proceeds until the ball is in the hole (distance to the hole is zero), and then the program informs the user of their score.
• The players score is the number of shots taken to get the ball in the hole. The final output will display the number of shots taken and how this relates to par. If their score is less than par for this hole, output is “under par”, equal to par is called “par”, and more than par is “over par”. See sample output for exact outputs.
After 10 hits, the ball is in the hole! Disappointing. You are 5 over par.
After 5 hits, the ball is in the hole! And that’s par.
After 3 hits, the ball is in the hole! Congratulations, you are 2 under par.
• If the player has done a previous round (i.e. this is the second time the game is played), the game should then display the total score with an appropriate message, and then show the game menu again.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

##The below given program works as given in the question using recurssion.

#importing random function
from random import randrange
#recursion function for play option
def play(dis,n=0):
if(dis==0):
return (int(n))
#input for the club
k=input("Choose the club (D)river,(I)ron,(P)utter")
if(k=="D"):
p=randrange(80,120,1)
dis=dis-p
n=n+1
print("Your shot went "+str(p)+"m.\nYou are "+str(abs(dis))+"m from the hole, after "+str(n)+" shot/s.")
return play(abs(dis),n)
if(k=="I"):
p=randrange(24,36,1)
dis=dis-p
n=n+1
print("Your shot went "+str(p)+"m.\nYou are "+str(abs(dis))+"m from the hole, after "+str(n)+" shot/s.")
return play(abs(dis),n)
if(k=="P"):
p=randrange(20,80,10)
p=max(p/10,1)
dis=dis-p
n=n+1
print("Your shot went "+str(p)+"m.\nYou are "+str(abs(dis))+"m from the hole, after "+str(n)+" shot/s..")
return play(abs(dis),n)
else:
#for any other input other than the clubs , even if small letters are treated as different input
print("Please select a valid club")
play(abs(dis),n)
#input name
name=input("Hey There What's Your Name : ")
print("Welcome to the game "+name)
#for input of par for ensuring its between 3 and 5
T=False
while(not T):
par = int(input("Whats the par : "))
if(par>=3 and par <=5):
T=True
else:
print("please enter value between 3 and 5")
##for input of distance for ensuring its between 195 and 250

while(T):
distance = int(input("What the distance to the hole for this game is "))
if(distance>=195 and distance <=250):
T=False
else:
print("please enter value between 195 and 250")
  
Q=True
while(Q):
print("(I)nstructions\n(P)lay\n(Q)uit")
i=str(input(" "))
if(i=='Q'):
print("<<Farewell and thanks for playing "+name+">>")
Q=False
elif(i=='I'):
print("This is a simple golf game in which each hole is "+str(distance)+"m game away with par "+str(par)+". You are able to choose from 3 clubs, the Driver, Iron or Putter. The Driver will hit around 100m, the Iron around 30m and the Putter around 10m. The putter is best used very close to the hole.")
elif(i=="P"):
print("The distace to the hole is "+str(distance))
l = play(distance)
print("After "+str(l)+" hits, the ball is in the hole!")
if(int(l)>par):
print(" Disappointing. You are "+str(int(l)-par)+" over par. ")
if(int(l)==par):
print("And that’s par.")
if(int(l)<par):
print(" Congratulations, you are "+str(par - int(l))+" under par.")

Add a comment
Know the answer?
Add Answer to:
Please help as it is very important task for me please write in Python code and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • hi can you please solve this python problem for me?? Three pets live in a happy...

    hi can you please solve this python problem for me?? Three pets live in a happy house: dog, cat and a mouse. The dog often chases the cat, the cat likes to chase the mouse, however the mighty dog runs away when it sees the mouse. Develop a game which can be played by two players. The program asks the two players (player1 and player2) to choose either 1 for dog, 2 for cat, or 3 for mouse. The rules...

  • python question Question 1 Write a Python program to play two games. The program should be...

    python question Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play each game. Call the file containing your program fun games.py. Your program should include the following functions: • function guess The Number which implements the number guessing game. This game is played against the computer and outputs the result of the game (win/lose) as well as number of guesses the user made to during the...

  • Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

    Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • (C++) Please create a tic tac toe game. Must write a Player class to store each...

    (C++) Please create a tic tac toe game. Must write a Player class to store each players’ information (name and score) and to update their information (increase their score if appropriate) and to retrieve their information (name and score).The players must be called by name during the game. The turns alternate starting with player 1 in the first move of round 1. Whoever plays last in a round will play second in the next round (assuming there is one).The rows...

  • In C++ program Fishing Game Simulation   For this assignment, you will write a program that simulates a fishing game. In this game, a six-sided die is rolled to determine what the user has caught. Eac...

    In C++ program Fishing Game Simulation   For this assignment, you will write a program that simulates a fishing game. In this game, a six-sided die is rolled to determine what the user has caught. Each possible item is worth a certain number of fishing points. The points will not be displayed until the user has finished fishing, and then a message is displayed congratulating the user depending on the number of fishing points gained.   Here are some suggestions for the...

  • This is python3. Please help me out. Develop the following GUI interface to allow the user...

    This is python3. Please help me out. Develop the following GUI interface to allow the user to specify the number of rows and number of columns of cards to be shown to the user. Show default values 2 and 2 for number of rows and number of columns. The buttons "New Game" and "Turn Over" span two column-cells each. Fig 1. The GUI when the program first starts. When the user clicks the "New Game" button, the program will read...

  • (C++) Hey guys we just went over loops and it got me confused, it has me...

    (C++) Hey guys we just went over loops and it got me confused, it has me scrathcing my head for the past two days. I would appreciate any help you guys have to offer. Few places I have a hard time is get input and determine winner(cummulative part). Write a program that lets the user play the Rock, Paper, Scissors game against the computer. The computer first chooses randomly between rock, paper and scissors, but does not display its choice....

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

  • I need help figuring out how to code this in C++ in Visual Studio. Problem Statement:...

    I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT