Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON 3 CODE-------------------------------- John is playing a game and fighting against a monster. The monster attacks n times. Each time the monster attacks, the damage

PYTHON 3 CODE--------------------------------

John is playing a game and fighting against a monster. The monster attacks n times. Each time the monster attacks, the damage is different. The monster dies after all the attacks. john character initially has health h. The first two lines will input h and n respectively. And the following n lines, will input the damage value. We say that the character survived iff it's final health is greater than zero. You need to print if his character will survive by printing True, and printing False otherwise.

Input Format-------------------------

The first line contains h. The second line contains n. Following n lines contain the damage the monster does on each attack

Output Format----------------------

Print True if the character survives, and print False otherwise.

Sample Input ---------------------------

500 4 30 400 10 15

Sample Output ---------------------------

True

Explanation ------------------------

Here, h=500 and n=4. First attack that the monster did causes 30 damage, so current health is 500-30=470. Second attack that the monster did causes 400 damage, so current health is 470-400=70. Third attack that the monster did causes 400 damage, so current health is 70-10=60. Fourth attack that the monster did causes 400 damage, so current health is 60-15=45. As the current health is greater than zero which means that the character survived so we print True

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

3. Is IBMs program really a mentoring program? Why or why not?

Answered: 1 week ago