Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Power-up the Hero | Variable Scope, Nested Functions, and Closures
Functional Programming Concepts in Python
Osio 3. Luku 9
single

single

Challenge: Power-up the Hero

Pyyhkäise näyttääksesi valikon

Tehtävä

Pyyhkäise aloittaaksesi koodauksen

Create a factory function that generates custom power-ups for a hero. Each power-up should remember its own multiplier and apply it to a hero's base stat, demonstrating closure behavior by allowing the inner function to remember the multiplier provided to the outer function.

  • Define an inner function inside create_power_up that takes a single argument base_stat and multiplies it by multiplier.
  • Return this inner function from create_power_up.
  • Use create_power_up to create two power-ups: one that doubles and one that triples a stat.
  • Apply these power-ups to a hero's attack and defense stats and print the results.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 9
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt