Calling Functions

Learn to Code Today!

Learn 10x faster: coding, no-code and data skills. Join millions of users mastering new tech skills and accelerating their career with Enki.
Get started

This is part of “An intro to Coding” series of posts, with content from the Enki app. If you stumbled upon this, you can start from the beginning.

The robot instructions are almost done! We're getting hungry.

Let's do the part 3 of our recipe¹ now, the grilling of the sandwich:

💡 We can give input values to functions directly, they don't have to be variables. If you notice above, we passed in the duration string "3min" directly into the fry_the_sandwich_on_each_side function.

The recipe¹ instructions are complete.

Now it's time to run the functions we create as commands for the robot.

The final part of the code we're giving the robot is:

💡 The order in which we call the functions matters! You wouldn't want it to prepare the cheese after it fried the sandwich.

Now for the last part.

Let's tell the robot to run the make_a_grill_cheese_sandwich function:

That's it! Bon Appétit!

💡 You should give your functions explanatory names. A good rule is to use verb-noun combinations (prepare_ingredients). If your functions require two verbs or nouns for its identifier, it's probably doing too much and you should split it into separate functions.



Footnotes

[1] The recipe says:

Ingredients:

  • cheese
  • bread
  • butter
  • plate
  • bowl

Instructions:

1. prepare the ingredients
 - Grate the cheese in a bowl
 - Cut the bread into slices

2. build the sandwich
 - Butter the bread on both sides
 - Add the cheese to the sandwich

3. grill the sandwich
 - Preheat a pan
 - Fry the sandwich for three minutes on each side (or until golden brown)

About Enki

  • Fully personalized online up-skilling
  • Unlimited AI coaching
  • Designed by Silicon Valley experts

More articles

Meet your AI-enabled coach

Professional athletes have a coach for every aspect of their performance. Why can’t you for your work? Enki’s AI-powered coaching on-demand - combined with state of the art, structured learning content - makes this a reality.
1
1:1 AI Coaching
How do I remove duplicate emails?
Convert the list to a set and back to a list. Sets automatically remove duplicates.
2
Personalized Exercises
3
Interactive practice

Unlock full access to all skills on Enki with a 7-day free trial

Get started