0
0
Intro to Computingfundamentals~10 mins

Functions (reusable code blocks) in Intro to Computing - Draw & Build Visually

Choose your learning style9 modes available
Draw This - beginner

Draw a flowchart that shows how a function named 'greet' works. The function takes a name as input and prints 'Hello, [name]!'. Then show how the main program calls this function with the name 'Alice'.

5 minutes
Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Grading Criteria
Start and End symbols present for both main program and function
Function definition shown as a separate block
Parameter input to function clearly indicated
Function call from main program shown
Print statement inside function correctly shown
Flow direction arrows correctly connect steps
Solution
  +-------------------+          +-------------------------+
  |      Start        |          |      Start Function      |
  +-------------------+          +-------------------------+
            |                             |
            v                             v
  +-------------------+          +-------------------------+
  | Call greet('Alice')|--------->| Receive parameter name  |
  +-------------------+          +-------------------------+
            |                             |
            |                             v
            |                  +-------------------------+
            |                  | Print "Hello, [name]!"   |
            |                  +-------------------------+
            |                             |
            |                  +-------------------------+
            |                  |       End Function       |
            |                  +-------------------------+
            v                             |
  +-------------------+                  |
  |       End         |<-----------------+
  +-------------------+

This flowchart shows two parts: the main program and the function named 'greet'.

1. The main program starts and calls the function 'greet' with the input 'Alice'.

2. The function starts and receives the input parameter called 'name'.

3. Inside the function, it prints the message "Hello, Alice!" by inserting the input name into the greeting.

4. The function ends and returns control back to the main program.

5. The main program then ends.

This shows how functions let us reuse code by defining a block that can be called with different inputs.

Variations - 2 Challenges
[intermediate] Draw a flowchart for a function named 'add' that takes two numbers as input and returns their sum. Show the main program calling 'add' with 5 and 3, then printing the result.
[advanced] Draw a flowchart for a function named 'is_even' that takes a number as input and returns 'Yes' if the number is even, or 'No' if it is odd. Show the main program calling 'is_even' with 10 and printing the result.