Day 2: GitHub Copilot Training for Beginners

๐ŸŸฆ Day 2: Writing Functions with Copilot

๐ŸŽฏ Goal:

Learn how to write functions efficiently with GitHub Copilot by giving it smart hints through comments and function names.


๐Ÿง  Concept:

GitHub Copilot predicts what you're trying to do when you:

  • Write clear comments
  • Start a function definition
  • Follow proper coding structure

๐Ÿ”ง Step-by-Step Practice (Language: Python — but you can try others too)

✅ Example 1: Use a descriptive comment

# Check if a number is even

➡ Copilot suggests:

def is_even(n):
    return n % 2 == 0

✅ Example 2: Use a function name as a clue

def reverse_string(s):

➡ Copilot may suggest:

    return s[::-1]

๐Ÿ” Practice Set – Try these prompts

Type each comment or function name and observe what Copilot suggests. Accept (Tab) or cycle suggestions (Alt + ] and Alt + [):


๐Ÿ”น Basic Math Functions

# Find the factorial of a number
# Return the sum of a list
# Find the largest number in a list

๐Ÿ”น String Functions

# Count vowels in a string
# Check if a string is a palindrome
# Replace spaces with underscores in a sentence

๐Ÿ”น List/Array Operations

# Remove duplicates from a list
# Sort a list of dictionaries by key 'age'

๐Ÿ”น Date/Time Examples

# Get the current date and time
# Check if a given year is a leap year

๐Ÿ’ก Tips for Better Suggestions

✅ Do This ❌ Avoid This
Use specific comments Write vague comments
Name functions meaningfully Use unclear names like func1()
Use small problems Ask for huge complex apps

๐Ÿงช Mini Challenge

Write this as a comment and let Copilot help:

# Write a function to calculate grade from marks (90+ = A, 80+ = B, etc.)

Then try:

# Check if a number is prime

Modify the logic and observe how Copilot adapts to your changes.


๐Ÿ“ Summary of Day 2

  • ๐Ÿงญ Use comments or function names to guide Copilot
  • ๐Ÿ” Try different ways to phrase your intention
  • ๐Ÿงช Practice simple utilities, not entire applications yet
  • ✅ Review & test the code Copilot writes — don’t assume it's perfect


Previous Post Next Post