This year NTHU's I2P class is divided into two classes (Class A and Class B). To celebrate our first midterm the Domo decided to host a tournament between the 2 classes. Each class chooses one champion to represent them in a turn-based duel.

You are to simulate a turn-based battle between two characters.
Each character has three basic attributes:
HP (hit points) — health of the character.
Attack — determines how much damage they can deal.
Defense — reduces incoming damage.
Characters can receive buffs that modify these attributes before the battle starts.
Each buff can modify attack, defense, or HP using operations such as addition or multiplication.
You must implement a function composition system so that multiple buffs can be combined into a single function.
List of possible buffs are:
"atk_add val" : increases attack by val"atk_mul val" : multiplies attack by val"dfs_add val" : increases defense by val"dfs_mul val" : multiplies defense by valFor example if you have the given buffs:
your new F function will be
Given the code:
if __name__ == "__main__":
# Input format:
# name1 hp1 atk1 dfs1
# name2 hp2 atk2 dfs2
# n
# Then n lines:
# target cmd value
# (target is either name1 or name2)
n1, h1, a1, d1 = input().split()
n2, h2, a2, d2 = input().split()
c1 = Character(n1, int(h1), int(a1), int(d1))
c2 = Character(n2, int(h2), int(a2), int(d2))
n = int(input())
buffs_c1 = []
buffs_c2 = []
for _ in range(n):
target, cmd, val = input().split()
buff = buff_factory(cmd, float(val))
if target == c1.name:
buffs_c1.append(buff)
elif target == c2.name:
buffs_c2.append(buff)
c1.buff_func = compose_buffs(*buffs_c1)
c2.buff_func = compose_buffs(*buffs_c2)
winner, hp_left = battle(c1, c2)
print(f"{winner} wins with {hp_left:.1f} HP left.")
Simulate the Battle Between the 2 characters given the following rules:
The battle alternates turns:
The first character (c1) attacks first.
Then the second character (c2) attacks, and so on.
When a character’s HP becomes 0 or below, the battle ends.
Output the winner’s name and their remaining HP (1 decimal place).
Buffs will be applied EVERY round before attacking the other character (BUFF WILL STACK THROUGH THE ROUNDS)
The damage taken for the character will be max(1, attackers.attack - receiver.defense) "APPLY BUFF FIRST BEFORE ATTACKING"
Please refer to the following link to see the round by round break down explanation of the sample input if you are confused:
Link
<name1> <hp1> <attack1> <defense1>
<name2> <hp2> <attack2> <defense2>n<target1> <cmd1> <val1>
<target2> <cmd2> <val2>
...
<targetn> <cmdn> <valn>target — the character’s name receiving the buffcmd — one of the buff commands (e.g., atk_add, hp_mul, etc.)val — a floating-point or integer value
Constraints
1 ≤ hp, attack, defense ≤ 1000
0 ≤ n ≤ 20
val can be integer or float (1 ≤ val ≤ 10)
Character names are unique and contain only letters.
Output the winner's name and his/her hp with the following format
<winner_name> wins with <remaining_hp> HP left.