1. Import the Utilities module file The values used to populate the characters variable should be moved to an external text file and imported into the main script utilizing with open() and related...

2 answer below »


































1. Import the Utilities module file

The values used to populate the characters variable should be moved to an external text file and imported into the main script utilizingwith open()and related functions.* You must create the utility file from the video.


2. Import the pirates.txt file

The values used to populate the characters variable should be moved to an external text file and imported into the main script utilizingwith open()and related functions.* You must create the pirate file from the video.


3. Use the utilities module to randomly pick pirates for player and opponent.
Adjust the script so the user (player) can choose which attack they want to use (pattack).Note: The Computer Player (opponent) should still have the script randomly choose an attack (oattack).
4. Add a while loop so that the pirates are not the same.
5. Exception / Error handling must be added to the script. At no point should the user should be able to end the script prematurely with an invalid selection.

Use while True and exception. Use a print statement to ask the user to enter a number for the attack.


6. Player only - Create an if/elif statement to set the number entry to the correct attack.
7. Add a while loop so that the attacks are not the same. Use the utilities module.

8. Change your if/elif statement. Use the and to compare the attacks. All attacks must be used correctly.

9. Print a string that includes the player and the player's score.

10. Print a string that includes the opponent and the opponent's score.
For Number 2, A text file must be created from the swashbuckle.py
https://www.youtube.com/watch?v=cfSyspWlA0w

Answered 8 days AfterOct 11, 2021

Answer To: 1. Import the Utilities module file The values used to populate the characters variable should be...

Neha answered on Oct 18 2021
130 Votes
# STUDENT NAME HERE
# Python version
# Pirate Swashbuckle Fight Milestone 3
import random
# 1. Import the uti
lities file
import utilities
# 2. Import the pirates.txt file
my_file = open("pirates.txt", "r")
content = my_file.read()
pirates = content.split(",")
my_file.close()
# dodge > parry > thrust > dodge
attack =['dodge', 'parry', 'thrust']
# 3. Use the utilites to randomly pick pirates for player and opponent
player = random.choice(pirates)
opponent = random.choice(pirates)
# 4. Add a while loop so that the pirates are not the same
while True:
if player == opponent:
player = random.choice(pirates)
opponent = random.choice(pirates)
else:
break
print ("Advast ye swabs, a fight betwixt \n" + player + " & " + opponent + " 'tis bout to commence! ")
player_Score = 0
opponent_Score = 0
gameover = False
oattack = ''
while gameover == False:
# This has changed for milestone 3. The game will still end when the player or opponent reaches 3.
if player_Score >= 3:
print (player + " has vanquished " + opponent)
print ("Hip hip huzzah!")
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here