#WSQ08 – On To Functions

Functions. Pretty easy task. Here’s the list:

  • You will go back and do WSQ03 – Fun with Numbers again.
  • But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.
  • You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

Basically, we need to make every operation of WSQ03 to be converted into a function.

Let’s begin:

FullniceWSQ08

 

This time, I’m not going to give you a lot of explanations, this is a pretty simple task. Ask for two integers (a,b), then, send the parameters (a,b) to every function (don’t forget to type “def” when you’re going to name a function or it will not work).

At last, just call every function, because functions aren’t going to work by themselves until you call them.

We run the program:

RUNWSQ08

And we’re done. Kind of too easy, huh?

CC BY-SA 4.0 #WSQ08 – On To Functions by manuelmendezhijar is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.