Penalty Shootout

For this challenge you are going to write a computer program where the user tries to score a goal against the computer.

The user will be asked where do they want to shoot and will have to choose one of the following five options:

• TL: Top Left,
• BL: Bottom Left,
• M: Middle,
• TR: Top Right,
• BR: Bottom Right.

The computer will act as the goal keeper and randomly choose one of these options too.

The program will decide if there is a goal or not by comparing the user’s choice with the computer option.

Complete the code

We have started the code for you. You need to complete it further:

Video Tutorial

Create a second level where the computer can block up to two locations which are next to each other such as:

• Bottom left and right left,
• Bottom left and middle,
• Top right and middle,
• etc.

Give the end-user a choice: do they want to shoot the penalty or be the goal keeper? Adapt your code to cater for both options.

Create a program where the computer and the player take it in turn. The program adds up the scores and stops on a best of 5 scores. (e.g. 3-0, 4-1, 4-2, 5-3, 5-4)
[pms-restrict display_to=”not_logged_in” message=” “]

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

Python Code

```#Penalty Shootout - www.101computing.net/penalty-shootout/
import random

print("     ________________________________     ")
print("     |                              |     ")
print("     |                              |     ")
print("     |       Penalty Shootout       |     ")
print("     |                              |     ")
print("_____|______________________________|_____")
print("")
print("")

score = 0
for counter in range (1,6):
#Let the computer decides where it wants the goal to dive
options=["TL","BL","M","TR","BR"]
computerOption = random.choice(options)

#Now let's ask the user where they want to shoot
userOption = input("Where do you want to shoot? (TL, BL, M, TR or BR)")

#Then we can check if the goal blocked the ball or not
if userOption == computerOption:
print("The goal blocked it!")
else:
print("You scored a goal!")
score = score + 1
print("Your score so far is: " + str(score))

print("Game Over")
```
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 3.1 / 5. Vote count: 75

No votes so far! Be the first to rate this post.

As you found this challenge interesting...