AP Computer Science Principles

Create Performance Task – Python Practice Program

Purpose of This Lesson

This example Python program is designed to help students identify and understand the major programming concepts used in the College Board AP Computer Science Principles Create Performance Task.

Important: The comments in this example are for learning and classroom instruction. Students should not include explanatory comments in the code screenshots used for their Personalized Project Reference (PPR).

Concepts Students Need to Recognize

Complete Python Example

# ================================================================
# AP COMPUTER SCIENCE PRINCIPLES
# CREATE PERFORMANCE TASK - PYTHON PRACTICE EXAMPLE
# ================================================================
#
# PROGRAM: Cybersecurity Quiz
#
# PURPOSE:
# This program quizzes a user about basic cybersecurity concepts.
#
# The program:
#   1. Gets input from the user.
#   2. Stores multiple pieces of data in lists.
#   3. Uses a student-developed procedure/function.
#   4. Uses a parameter.
#   5. Uses sequencing.
#   6. Uses selection.
#   7. Uses iteration.
#   8. Calls the student-developed procedure.
#   9. Produces output.
#
# ================================================================


# ------------------------------------------------
# REQUIREMENT: LIST / DATA ABSTRACTION
# ------------------------------------------------
#
# A LIST stores multiple related pieces of information.
#
# The variable "questions" stores multiple questions.
#
# Lists make the program easier to:
#
#   - develop
#   - maintain
#   - modify
#   - expand
#   - process with loops
#
# Students should be prepared to explain HOW a list
# helps manage complexity in their program.
# ------------------------------------------------

questions = [
    "What type of attack attempts to trick a user into revealing information?",
    "Which password is the strongest?",
    "What does MFA stand for?",
    "What type of software protects a computer from malicious programs?",
    "What should you do with a suspicious email attachment?"
]


# ------------------------------------------------
# ANOTHER LIST
# ------------------------------------------------
#
# Each answer corresponds to a question at the same index.
#
# questions[0] matches answers[0]
# questions[1] matches answers[1]
# etc.
# ------------------------------------------------

answers = [
    "phishing",
    "T7#mQ9!zP2",
    "multi-factor authentication",
    "antivirus",
    "do not open it"
]


# ------------------------------------------------
# REQUIREMENT: STUDENT-DEVELOPED PROCEDURE
# ------------------------------------------------
#
# In Python, a procedure is normally called a FUNCTION.
#
# This function is named:
#
#       check_answer
#
# ------------------------------------------------
#
# REQUIREMENT: PARAMETERS
# ------------------------------------------------
#
# This function has TWO parameters:
#
#       user_answer
#       correct_answer
#
# Parameters allow a procedure to work with different data.
# ------------------------------------------------

def check_answer(user_answer, correct_answer):

    # ============================================================
    # ALGORITHM
    # ============================================================
    #
    # This procedure includes:
    #
    #       SEQUENCING
    #       SELECTION
    #       ITERATION
    #
    # ============================================================


    # ------------------------------------------------------------
    # SEQUENCING
    # ------------------------------------------------------------
    #
    # Sequencing means instructions execute in order.
    # ------------------------------------------------------------

    cleaned_answer = user_answer.lower()
    cleaned_answer = cleaned_answer.strip()


    # ------------------------------------------------------------
    # ITERATION
    # ------------------------------------------------------------
    #
    # Iteration means repeating instructions.
    #
    # This loop examines the answer one character at a time.
    # ------------------------------------------------------------

    character_count = 0

    for character in cleaned_answer:
        character_count = character_count + 1


    # ------------------------------------------------------------
    # SELECTION
    # ------------------------------------------------------------
    #
    # Selection allows the program to choose between
    # different paths.
    # ------------------------------------------------------------

    if cleaned_answer == correct_answer.lower():

        print("Your answer contained",
              character_count,
              "characters.")

        return True

    else:

        print("Your answer contained",
              character_count,
              "characters.")

        return False


# ================================================================
# MAIN PROGRAM
# ================================================================

score = 0


# ------------------------------------------------
# REQUIREMENT: INPUT
# ------------------------------------------------
#
# Input is data sent into the program.
# ------------------------------------------------

name = input("Enter your name: ")


# ------------------------------------------------
# REQUIREMENT: OUTPUT
# ------------------------------------------------
#
# Output is information produced by the program.
# ------------------------------------------------

print()
print("Welcome to the Cybersecurity Quiz,", name)
print("--------------------------------------")
print()


# ------------------------------------------------
# REQUIREMENT: ITERATION / LIST TRAVERSAL
# ------------------------------------------------
#
# The FOR LOOP processes each question in the list.
# ------------------------------------------------

for index in range(len(questions)):

    print()
    print("Question", index + 1)

    print(questions[index])


    # INPUT

    user_answer = input("Your answer: ")


    # ------------------------------------------------------------
    # REQUIREMENT: PROCEDURE CALL
    # ------------------------------------------------------------
    #
    # The procedure check_answer() is called here.
    #
    # user_answer and answers[index] are arguments.
    # ------------------------------------------------------------

    result = check_answer(user_answer, answers[index])


    # ------------------------------------------------------------
    # SELECTION
    # ------------------------------------------------------------

    if result == True:

        print("Correct!")
        score = score + 1

    else:

        print("Incorrect.")
        print("Correct answer:", answers[index])


# ================================================================
# FINAL OUTPUT
# ================================================================

print()
print("--------------------------------------")
print("QUIZ COMPLETE")
print("--------------------------------------")

print(name + ", your score is", score, "out of", len(questions))


# ------------------------------------------------
# MORE SELECTION
# ------------------------------------------------

if score == len(questions):

    print("Excellent! Perfect score.")

elif score >= 3:

    print("Good job. You understand many cybersecurity concepts.")

else:

    print("You should review the cybersecurity material.")


# ================================================================
# END OF PROGRAM
# ================================================================

What Students Should Be Able to Explain

AP CSP Concept Where It Appears What Students Need to Know
Input input() Information entered by the user and received by the program.
Output print() Information the program communicates to the user.
List questions and answers Stores multiple related values under one variable name.
Data Abstraction Lists Students should explain how the list reduces complexity in the program.
Procedure check_answer() A student-developed section of reusable code that performs a task.
Parameter user_answer and correct_answer Variables in the procedure definition that receive values.
Procedure Call check_answer(user_answer, answers[index]) The statement that causes the procedure to run.
Sequencing Statements inside check_answer() Instructions execute in a specific order.
Selection if, elif, else The program chooses between different paths based on a condition.
Iteration for loops A section of code repeats multiple times.
Algorithm check_answer() A set of steps that uses sequencing, selection, and iteration to perform a task.

Understanding Data Abstraction

Possible Exam Question:

How does the use of the list manage complexity in your program?

A strong student explanation could be:

The questions list stores all quiz questions in one data structure. The program can use a loop to process every question instead of creating a separate variable and separate statements for each question. This makes the program easier to maintain, modify, and expand.

Understanding the Student-Developed Procedure

def check_answer(user_answer, correct_answer):

    cleaned_answer = user_answer.lower()
    cleaned_answer = cleaned_answer.strip()

    character_count = 0

    for character in cleaned_answer:
        character_count = character_count + 1

    if cleaned_answer == correct_answer.lower():
        return True
    else:
        return False

This procedure demonstrates the following:

Procedure Call

result = check_answer(user_answer, answers[index])

The procedure must not simply be defined. It must also be called somewhere in the program.

Parameters vs. Arguments

Term Example
Parameters user_answer, correct_answer
Arguments user_answer, answers[index]

Exam Preparation Areas

Area Students Should Be Prepared to Explain
Program Design, Function, and Purpose What the program does, why it was created, its input, and its output.
Algorithm Development How sequencing, selection, and iteration work together.
Errors and Testing Test cases, expected results, possible errors, and corrections.
Data and Procedural Abstraction How lists and procedures reduce complexity and organize the program.

Testing Practice

Students should be able to create test cases such as:

Test Input Expected Result
Correct answer phishing The program reports that the answer is correct.
Different capitalization PHISHING The program still accepts the answer because it converts the input to lowercase.
Incorrect answer virus The program reports that the answer is incorrect.
Teacher Recommendation: Use this program as a practice and annotation activity. Have students locate and label the list, procedure, parameter, procedure call, sequencing, selection, iteration, input, and output before they begin their own Create project.
Academic Integrity: This example should be used for instruction and practice. Students should create and understand their own program for the official AP CSP Create Performance Task and follow current College Board rules for attribution and submission.