Python Basics with Copilot Prompts

Welcome to Module 2! In this module, we’ll explore the most fundamental parts of Python: variables, data types, input/output, operators, and comments.

You’ll learn all of these by writing simple prompts for Copilot in VS Code and seeing the code it generates for you. Let’s start!

Variables and Data Types

Variables are like boxes where you store data. In Python, you can store different types of data: numbers, text, lists, and more.

Prompt

1
# Create examples of different data types in Python (int, float, string, boolean, list, tuple, set, dict)

When you write this prompt and start typing, Copilot may suggest code like this:

python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Integer
age = 25

# Float
height = 5.9

# String
name = "Alice"

# Boolean
is_student = True

# List
colors = ["red", "green", "blue"]

# Tuple
coordinates = (10, 20)

# Set
unique_numbers = {1, 2, 3}

# Dictionary
person = {"name": "Alice", "age": 25}

Explanation

  • Integer (int): Whole numbers (e.g., 25).
  • Float: Numbers with decimal points (e.g., 5.9).
  • String (str): Text (e.g., "Alice").
  • Boolean (bool): True or False values.
  • List: Ordered collection that can be changed (e.g., list of colors).
  • Tuple: Ordered collection that cannot be changed (e.g., coordinates).
  • Set: Collection of unique items, no duplicates.
  • Dictionary (dict): Key-value pairs (e.g., a person’s details).

Activity

  • Try changing values or adding your own examples.
  • Ask Copilot to create a new variable for your favorite food, favorite number, etc.

Basic Input/Output

Input and output help you interact with your program. You can ask the user for information and print messages back.

Prompt

1
# Write a Python program to take user input and print it formatted

When you type this, Copilot may suggest:

python
1
2
3
4
name = input("What is your name? ")
age = input("How old are you? ")

print(f"Hello, {name}! You are {age} years old.")

Explanation

  • input() lets you get text from the user.
  • print() shows output on the screen.
  • f"..." is called an f-string — it allows you to insert variable values directly inside curly braces {}.

Activity

  • Ask Copilot to write another prompt to get a user's favorite color and print a message like: "Wow! Blue is a great choice!"
  • Try different questions and create a small interactive program.

Operators

Operators let you perform calculations and comparisons in your code.

Prompt

1
# Show examples of arithmetic and logical operators in Python

Copilot might suggest:

python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Arithmetic operators
a = 10
b = 3

addition = a + b        # 13
subtraction = a - b     # 7
multiplication = a * b  # 30
division = a / b       # 3.333...
modulus = a % b        # 1
power = a ** b         # 1000

# Comparison operators
is_equal = a == b      # False
is_greater = a > b    # True

# Logical operators
x = True
y = False

and_result = x and y   # False
or_result = x or y     # True
not_result = not x     # False

Explanation

Arithmetic operators

  • +, -, *, /, %, **: Basic math.

Comparison operators

  • ==, >, <, !=: Check relationships between values and return True or False.

Logical operators

  • and, or, not: Combine or reverse logical conditions.

Activity

  • Ask Copilot to write a function that returns True if a number is both greater than 5 and even.
  • Try using different numbers to see if your logic works.

Comments and Code Readability

Comments help you and others understand what your code does. They don’t affect how your code runs.

Prompt

1
# Add comments explaining this code snippet

Let’s say you have this code:

python
1
2
def add_numbers(a, b):
    return a + b

After writing the prompt and typing #, Copilot might suggest:

python
1
2
3
4
# This function takes two numbers, a and b
# It returns the sum of a and b
def add_numbers(a, b):
    return a + b

Explanation

  • Comments start with # in Python.
  • You should use them to describe what each part of your code does, especially if you're sharing or reading it later.

Activity

  • Ask Copilot to add comments to a code snippet that finds the maximum of two numbers.
  • Practice writing your own comments explaining each step in simple words.

Key Takeaways

  • Use prompts to guide Copilot clearly — always be specific and simple.
  • Learn about basic data types and try making small examples for each.
  • Practice writing input/output code to interact with users.
  • Use operators to perform calculations and logic checks.
  • Add comments to make your code easy to read and understand.

Mini Project: Your First Python Info Card

Prompt

1
# Write a Python program that asks for your name, favorite hobby, and age, then prints a short introduction using those details

Frequently Asked Questions