Objective Use input() to allow the user to name the badguy . Explain what is happening with time.sleep(2). Explain how goodguy and badguy hit points are generated. What purpose does '\n' serve? Locate...

1 answer below »


















































Objective
Use input() to allow the user to name thebadguy.
Explain what is happening with time.sleep(2).
Explain howgoodguyandbadguyhit points are generated.
What purpose does '\n' serve?
Locate & Correct the syntax errors.
Explain how the value indamageis calculated.
Correct the syntax error in the last conditional statement.
Print a congratulatory statement using the name of the winner (either goodguy or badguy).

Answer the following Questions (place in the script as comments)
What Condition will end the WHILE Loop?
How is that Condition handled in the code?
What events happen inside the WHILE Loop?
Why aregghealth&bghealthinitially set outside the WHILE Loop?





knight_fight.py # [YOUR NAME HERE] # Python 2.7.10 # Tale of the Black Knight # The random module provides access to random related functions # The time module provides access to time related functions import random import time goodguy = str(raw_input("Enter your Knight's Name: ")) goodguy = "Sir " + goodguy # Here, we are assigning the value 'The Black Knight' to the variable badguy # 1. CHANGE THIS LINE SO THE USER CAN ENTER A VALUE FOR BADGUY badguy = "Bad Guy" badguy = "Sir " + badguy # Once Upon A Time... print goodguy + ", a Knight in search of adventure, is wandering through the enchanted forest one day." # 2. WHAT ACTION IS THIS LINE PERFORMING? # A: time.sleep(2) print "As " + goodguy + " reaches a clearing, he encounters the fearsome " + badguy + "!" time.sleep(2) print goodguy + ": You, Sir, are a Blackguard and a coward! I challenge you to a duel!" print badguy + ": I'mma cut you, fool!" # Good Guy Health gghealth = 100 # Bad Guy Health bghealth = 100 # Fight Sequence Loop while True: # 3. EXPLAIN HOW GOODGUY / BADGUY HIT POINTS ARE GENERATED # A: # Good Guy / Bad Guy Hit Points gghit = random.randint(1, 100) bghit = random.randint(1, 100) # ####################################################### # 4. WHAT PURPOSE DOES '\n' SERVE? # A: print "\n" # 5. FIND & CORRECT THE SYNTAX ERRORS. COMMENT OUT THE INCORRECT LINE AND # WRITE THE CORRECT CODE UNDERNEATH print goodguy + " rolls a " + gghit print badguy + " rolls a " + bghit # 6. EXPLAIN HOW THE VALUE IN DAMAGE IS CALCULATED # A: # Damage Calculator if gghit > bghit: damage = gghit - bghit bghealth = bghealth - damage print goodguy + " strikes " + badguy + " for a " + str(damage) + " hit!\n" if bghealth >= 100: print badguy + ": Thou hast missed.\n" elif bghealth >= 75: print badguy + ": Tis but a flesh wound.\n" elif bghealth >= 50: print badguy + ": Alas! A fair strike! En garde!\n" elif bghealth >= 25: print badguy + ": Thou art a worthy opponent.\n" elif bghealth < 10:="" print="" badguy="" +="" ":="" i="" am="" beaten.="" well="" fought...\n"="" break="" #="" #######################################################="" elif="" bghit=""> gghit: damage = bghit - gghit gghealth = gghealth - damage print badguy + " strikes " + goodguy + " for a " + str(damage) + " hit!\n" # 7. CORRECT THE SYNTAX ERROR(S) if gghealth = 100: print goodguy + ": Thou hast missed.\n" elif gghealth >= 75: print goodguy + ": Tis but a flesh wound.\n" elif gghealth >= 50: print goodguy + ': Alas! A fair strike! En garde!\n' elif gghealth >= 25: print goodguy ": Thou art a worthy opponent.\n" elif gghealth < 10: print goodguy + ": i am beaten. well fought...\n" break # ####################################################### # end of loop ############################################### # 8. print a congratulatory statement here using the name of the winner (goodguy or badguy) print "end of the knight fight\n" # 9. part 2 ''' in your own words, answer the following 4 questions on the use of the while loop in the script from part 1: 1. what condition will end the while loop? 2. how is that condition handled in the code? 3. what events happen inside the while loop? 4. why are gghealth & bghealth initially set outside the while loop? ''' # 10. after completing upload your completed script as a .zip file to fso __macosx/._knight_fight.py 10:="" print="" goodguy="" +="" ":="" i="" am="" beaten.="" well="" fought...\n"="" break="" #="" #######################################################="" #="" end="" of="" loop="" ###############################################="" #="" 8.="" print="" a="" congratulatory="" statement="" here="" using="" the="" name="" of="" the="" winner="" (goodguy="" or="" badguy)="" print="" "end="" of="" the="" knight="" fight\n"="" #="" 9.="" part="" 2="" '''="" in="" your="" own="" words,="" answer="" the="" following="" 4="" questions="" on="" the="" use="" of="" the="" while="" loop="" in="" the="" script="" from="" part="" 1:="" 1.="" what="" condition="" will="" end="" the="" while="" loop?="" 2.="" how="" is="" that="" condition="" handled="" in="" the="" code?="" 3.="" what="" events="" happen="" inside="" the="" while="" loop?="" 4.="" why="" are="" gghealth="" &="" bghealth="" initially="" set="" outside="" the="" while="" loop?="" '''="" #="" 10.="" after="" completing="" upload="" your="" completed="" script="" as="" a="" .zip="" file="" to="" fso="">
Answered 1 days AfterOct 07, 2021

Answer To: Objective Use input() to allow the user to name the badguy . Explain what is happening with...

Neha answered on Oct 09 2021
123 Votes
93120 - python code/knight_fight.py
# [YOUR NAME HERE]
# Python 2.7.10
# Tale of the Black Knight
# The random module provides access to random r
elated functions
# The time module provides access to time related functions
import random
import time
goodguy = str(raw_input("Enter your Knight's Name: "))
goodguy = "Sir " + goodguy
# Here, we are assigning the value 'The Black Knight' to the variable badguy
# 1. CHANGE THIS LINE SO THE USER CAN ENTER A VALUE FOR BADGUY
badguy = input("Please enter a value for bad guy")
badguy = "Sir " + badguy
# Once Upon A Time...
print goodguy + ", a Knight in search of adventure, is wandering through the enchanted forest one day."
# 2. WHAT ACTION IS THIS LINE PERFORMING?
# A:this line pause the code for 2 seconds. This creates a sleep time for the code.
time.sleep(2)
print "As " + goodguy + " reaches a clearing, he encounters the fearsome " + badguy + "!"
time.sleep(2)
print goodguy + ": You, Sir, are a Blackguard and a coward! I challenge you to a duel!"
print badguy + ": I'mma cut you, fool!"
# Good Guy Health
gghealth = 100
# Bad Guy Health
bghealth = 100
# Fight Sequence Loop
while True:
# 3. EXPLAIN HOW GOODGUY / BADGUY HIT POINTS ARE GENERATED
# A: It will generate the hit points for GOODGUY / BADGUY using random numbers. The random number will be generated between 1 and 100.
# Good Guy / Bad Guy Hit Points
gghit = random.randint(1, 100)
bghit = random.randint(1, 100)
#...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here