PYTHON PROGRAMS
PROGRAM 01 – SIR CONNOR VS LIVE YUG
PROGRAM DESCRIPTION
Sir Connor,
our gentlemanly protagonist, must fight the epic villain Live Yug. Sir Connor has a power level of 12 and Live Yug has a power level of 16.
The power
level can be used to calculate both the max damage and max health points for
each character using the following formulae:
Max damage = 2 + power level
Max health points = 10 + (2 x power
level)
The battle
between both legendary characters can only end in the death of one of the
two. Write a program that will
simulate this memorable battle. This
battle will consist of many rounds with each one looking like this:
Sir Connor will do damage to Live
Yug.
Live Yug
will do damage to Sir Connor.
If both are still alive, another
round will take place.
There is a
catch. Sir Connor has in his
possession the Cheese Curds of Power which give +3 damage to all his attacks. (I apologize for the cheesy joke.)
DETAILS
In any round,
the damage done by a character is a random number between 0 and the maximum
damage. Except, because of his special
artifact, Sir Connor also gets +3 added to his damage.
The result of
each round needs to be outputted to screen.
You should also be outputting the health of each character to the
screen.
When the
battle is over, the program needs to output the winner.
It is possible that both characters die in the same round. Your program should handle this situation
with an appropriate output message.
GENERAL GUIDE
If you feel
you are capable of creating this program without a guide, then you are welcome
to use your own approach. If help
would be useful, then read on.
- Start by creating a function called scdmg that returns the damage done by Sir
Connor. It first generates a
random number between 0 and Sir Connor’s max damage. Then, it adds three to that value and
returns it.
- Next create a function called lydmg
that returns the damage done by Live Yug. Similarly, the function returns a
random value between 0 and Live Yug’s max
damage.
- In the main program section, create a variable
called schp that represents Sir Conor’s health points. It needs to be initialized to Sir Conor’s max health to start.
- Next, create a similar variable called lyhp that represents Live Yug’s
health. Initialize it to Live Yug’s max health.
- Next, create the loop that will repeat as long as
both characters are alive. In
other words, the program will loop while schp
is greater than zero and lyhp is greater than
zero.
- Inside the loop, you need four statements.
- The first creates a variable that
is set to the call to the scdmg function. So it has the value of Sir Conor’s damage this round.
- The next statement reduces
Live Yug’s health by the damage in a.
- The third statement creates a
variable that gets the result of the function call to the function lydmg.
Essentially, it is the same as in a but for the opposite
character.
- The last statement reduces Sir
Connor’s health by the damage in c.
7.
After the
loop, we simply have to output the result of the battle. If schp is
greater than zero, then we know that Sir Connor won. If lyhp is
greater than zero, then we know that Live Yug
won. If both hp
values are zero or below, then both characters have been defeated.
|