Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Basic Smores Recipe | Mastering Python Decorators
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Functional Programming Concepts in Python

bookChallenge: Basic Smores Recipe

Task

Swipe to start coding

When you run this script, it should output the layers of a smore in the correct order: cracker, chocolate, marshmallow, cracker.

This exercise demonstrates the concept of how decorators wrap functionality around a function in Python.

  1. In the wrapper function of the crackers decorator, you need to call the function being decorated (i.e., func). This should be done between the two print statements;
  2. Ensure that the function func is called with any arguments and keyword arguments it might receive;
  3. Similar to the crackers decorator, the chocolate decorator should call the function it's decorating.
  4. The main task is to put decorators in right sequence. You must receive:
               ~~cracker~~
-roasted-------marshmallow-
               =chocolate=
               ~~cracker~~

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 6
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain what this video is about?

How can I customize the appearance of the video player further?

Is there a way to add subtitles or captions to this video?

close

bookChallenge: Basic Smores Recipe

Swipe to show menu

Task

Swipe to start coding

When you run this script, it should output the layers of a smore in the correct order: cracker, chocolate, marshmallow, cracker.

This exercise demonstrates the concept of how decorators wrap functionality around a function in Python.

  1. In the wrapper function of the crackers decorator, you need to call the function being decorated (i.e., func). This should be done between the two print statements;
  2. Ensure that the function func is called with any arguments and keyword arguments it might receive;
  3. Similar to the crackers decorator, the chocolate decorator should call the function it's decorating.
  4. The main task is to put decorators in right sequence. You must receive:
               ~~cracker~~
-roasted-------marshmallow-
               =chocolate=
               ~~cracker~~

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 6
single

single

some-alt