Dark theme

What this change means, is we can use the function with different monsters, so, for example:

    decision = input("You come to a junction. Turn left or right [L,R]: ")

    if decision == "L" or decision == "l":
        print("You turn left and see a terrible ogre and a horrible troll!")
        ogre_strength = 2
        fight(ogre_strength)
        troll_strength = 3
        fight(troll_strength)

Indeed, as we never use these variables again, we can just do:

    decision = input("You come to a junction. Turn left or right [L,R]: ")

    if decision == "L" or decision == "l":
        print("You turn left and see a terrible ogre and a horrible troll!")
        fight(2)
        fight(3)

What's happening is exactly what happens with something like print("hello world") - the value "hello world" is being attached to a variable inside the function, which is used to put the value on the screen. Note that, helpfully, we don't need to know the name of the variable, though you will sometimes see people use:

        fight(monster_strength=2)

for reasons we don't need to worry about at the mo.

I suppose it might be nice, if we have multiple monsters, if the player knew who they were fighting...

[Home > Part 3 > Next]