Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Power-up the Hero | Variable Scope, Nested Functions, and Closures
Functional Programming Concepts in Python
Seção 3. Capítulo 9
single

single

Challenge: Power-up the Hero

Deslize para mostrar o menu

Tarefa

Deslize para começar a programar

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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 9
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt