Practice For Loop, While Loop, and Functions
Step 1: Ask the student to calculate the sum of numbers from 1 to 10 using a for loop.
Step 2: Initialize a total variable to store the sum.
Step 3: Use the loop to add each number to the total.
Step 1: Ask the student to print all even numbers between 1 and 20 using a for loop.
Step 2: Check if a number is even using the modulus operator.
Step 1: Ask the student to calculate the sum of numbers from 1 to 10 using a while loop.
Step 2: Initialize a counter and total variable.
Step 3: Add numbers using the while loop and increment the counter each time.
Step 1: Ask the student to print all even numbers from 1 to 20 using a while loop.
Step 2: Use a counter to iterate and check if a number is even.
Step 1: Create a function that prints a greeting message.
Step 2: Call the function to display the message.
Step 1: Create a function that accepts a name as a parameter.
Step 2: Print a greeting message using the name parameter.
Step 3: Call the function with different names.
Step 1: Create a function that returns the square of a number.
Step 2: Store the returned value in a variable and print it.
Step 1: Create a function with a default name parameter.
Step 2: Call the function without a parameter and with a parameter.
Step 1: Create a function that sums numbers from 1 to n using a for loop.
Step 2: Return the total sum and call the function with a sample number.
Step 1: Create a function that sums numbers from 1 to n using a while loop.
Step 2: Initialize counter and total inside the function, update total in the loop, and return it.