Hero damage

Report a typo

Let's now take a look at how global variables can help us save information between different function calls.

Imagine you're writing a program for a video game: you need to calculate the damage that the main hero deals to enemies in one hit. The current damage is stored in the global variable hero_damage. Use this global variable to write three functions that change its value:

  • double_damage(): doubles the hero's damage

  • disarmed(): reduces the damage to 10% of its current value

  • power_potion(): adds 100 damage points

The functions are already declared. You only need to replace the pass keyword with your own code.

Don't output or return anything; just write the body of the functions. Remember how to modify the value of a global variable within a function.

Write a program in Python 3
hero_damage = 100


def double_damage():
pass


def disarmed():
pass


def power_potion():
pass
___

Create a free account to access the full topic