Please enable JavaScript to use CodeHS

Sample A CSP Performance Task

By David Burnham

Part 1: Full Code

Part 2: Video

Part 3: Written Response

3A.

Provide a written response that does all three of the following: 

i. Describes the overall purpose of the program

ii. Describes what functionality of the program is demonstrated in the video

iii. Describes the input and output of the program demonstrated in the video

?


The purpose of this program is to test basic math problems in multiplication and division and report the percent correct back to the user. The video demonstrates both the multiplication and division quizzes where the user is asked for the problem type and then given 5 problems, each with a chance to answer and the results reported back.


The video demonstrates 2 different inputs and 3 different outputs. The inputs demonstrated are asking users to select a problem type and then providing a guess for the problems. The three outputs demonstrated are outputting the problem, outputting the results from each guess, and outputting the final score at the end.

3B.

Capture and paste two program code segments you developed during the administration of this task that contain a list (or other collection type) being used to manage complexity in your program.

i. The first program code segment must show how data have been stored in the list. 

ii. The second program code segment must show the data in the same list being used, such as creating new data from the existing data or accessing multiple elements in the list, as part of fulfilling the program’s purpose. 

Then, provide a written response that does all three of the following:

iii. Identifies the name of the list being used in this response

iv. Describes what the data contained in the list represent in your program

v. Explains how the selected list manages complexity in your program code by explaining why your program code could not be written, or how it would be written differently, if you did not use the list 

?


First code segment:

first_number = [8, 12, 6, 20, 10]
second_number = [2, 3, 3, 4, 5]

Second code segment:

print(first_number[i], end = " "),
if (type == "M"):
    print("*", end=" "),
    correct = first_number[i] * second_number[i]
else:
    print("/", end = " "),
    correct = first_number[i] / second_number[i]
print(second_number[i])


The program uses two lists, first_number and second_number. Each list stores the values that are used in the math problems. first_number stores the first number in the problem and second_number stores the second number, which is the divisor for division problems.


The lists manages complexity in two different ways. First, by using the lists instead of individual variables, the list can store all the values in one variable and use a loop to create the problem. This also allows the program to expand easily by setting the loop length to the length of the lists. Without list, the program would have to use individual variables and written sequentially instead of with a loop.


Additionally, by storing the specific values for the problem it allows for the program to create division problems that result in integer answers. If the program generated random numbers, it would be much more complex to create problems that would result in integer answers.

3C.

Capture and paste two program code segments you developed during the administration of this task that contain a student-developed procedure that implements an algorithm used in your program and a call to that procedure.

i. The first program code segment must be a student-developed procedure that:

• Defines the procedure’s name and return type (if necessary)

• Contains and uses one or more parameters that have an effect on the functionality of the procedure

• Implements an algorithm that includes sequencing, selection, and iteration

ii. The second program code segment must show where your student-developed procedure is being called in your program.

Then, provide a written response that does both of the following:

iii. Describes in general what the identified procedure does and how it contributes to the overall functionality of the program

iv. Explains in detailed steps how the algorithm implemented in the identified procedure works. Your explanation must be detailed enough for someone else to recreate it.



First code segment:

def calculate(type):
    score = 0
    for i in range(num_problems):
        print(first_number[i], end = " "),
        if (type == "M"):
            print("*", end=" "),
            correct = first_number[i] * second_number[i]
        else:
            print("/", end = " "),
            correct = first_number[i] / second_number[i]
        print(second_number[i])
        answer = int(input("Enter your answer:"))
        if answer == correct:
            print("Correct!")
            score += 1
        else:
            print("Good try!")
        print()
    return score


Second code segment:

score = calculate(type) * 100 / num_problems


The selected function contributes to the overall execution of the program by executing the quiz questions and returning how many questions were correct. The function takes the type of questions as an input and then returning the number of correct answers back to the main program.


The function does this by looping through all the values in the list to create a problem. Inside the loop, the function starts by printing out the first number of the problem from the first_number list. It then uses a selection statement to print out the operator and calculate the correct answer for either a division or multiplication problem based on the passes parameter. Next, it prints out the second number from the second_number list and asks the user for their guess. Using a selection statement, it compares the correct answer to the user's input and reports out the results. If the answer is correct, it also adds to a tracker variable that keeps track of the number of correct answers. At the end of the loop, the function terminates by returning the number of correct answers.

3D.

Provide a written response that does all three of the following:

i. Describes two calls to the procedure identified in written response 3c. Each call must pass a different argument(s) that causes a different segment of code in the algorithm to execute.

ii. Describes what condition(s) is being tested by each call to the procedure

iii. Identifies the result of each call



The two test cases are based on passing a different input to create different types of problem in the function (multiplication versus division). The first call will pass the letter M. Based on this call, the program should select a multiplication problems to print out. Inside the loop, the selection statement will execute the first part of the selection statement and print a problem with a * operator. It will also calculate the answer by multiplying the values from the first_number and second_number lists. The result of the call will be to print 5 multiplication problems and return the number of correct answers.


The second call will pass the letter D. Based on this call, the program should select a multiplication problem. Inside the loop, the selection statement will execute the else clause since D does not equal M. As a result, the code will print a / operator and calculate the answer by dividing the first_number value by the second_number value. The result of the call will be to print 5 division problems and return the number of correct answers.

Scoring Commentary


6/6

Row 1:

The response earned the point for this row, meeting all six criteria:

• The video demonstrates the program receiving user input for both the problem type and the answers to the problem

• The program's purpose is to create a math quiz and the video demonstrates creating both a multiplication and division quiz.

• The program demonstrates output by creating the problems and displaying the results of each problem and the quiz

• The input and output is described in the response by stating "The inputs demonstrated are asking users to select a problem type and then providing a guess for the problems. The three outputs demonstrated are outputting the problem, outputting the results from each guess, and outputting the final score at the end."


Row 2:

The response earned the point for this row, meeting all three criteria:

• Two distinct code segments are shown

• The name of the list is described as first_number

• The response states what values are stored in the list: "first_number stores the first number in the problem"


Row 3:

The response earned the point for this row, meeting both criteria: 

• The response includes the two lists first_number and second_number and are used in a loop to generate multiple problems

• The response explains how it manages complexity by stating "the list can store all the values in one variable and use a loop to create the problem." It also explains how the program would need to be written without a list by stating "Without list, the program would have to use individual variables and written sequentially instead of with a loop."


Row 4:

The response earned the point for this row, meeting both criteria: 

• The response includes two distinct code segments, one defining a function calculate with the type parameter and the other calling this function

• The response describes what the procedure does by stating "The function taking the type of questions as an input and then returning the number of correct answers back to the main program" and describes how it relates to the overall function by stating "The selected function contributes to the overall execution of the program by executing the quiz questions and returning how many questions were correct."


Row 5:

The response earned the point for this row, meeting both criteria: 

• The selected algorithm includes sequencing, selection (two if statements), and iteration (for loop for the problems)

• The response includes a detailed explanation of how to recreate the algorithm int he second paragraph of 3C.


Row 6:

The response earned the point for this row by meeting all three criteria:

• Two different calls are described, M and D. For each, the code segment that is executed is described. For example, "Inside the loop, the selection statement will execute the first part of the selection statement and print a problem with a * operator."

• For each call, the condition being tested is described. "The two test cases are based on passing a different input to create different types of problem in the function (multiplication versus division)."

• The result of each call is described in the response: "The result of the call will be to print 5 multiplication problems and return the number of correct answers."