ap csp variables assignments expressions strings (3.1, 3.3, 3.4)
A teacher is writing a code segment that will use variables to represent a student's name and whether or nor the student is currently absent. Which of the following variables are most appropriate for the code segment?
A string variable named studentName and a Boolean variable named isAbsent
Which of the following are benefits of using well-named variables in a computer program? Select two answers.
The people will be easier for people to read. The program will be easier to modify in the future.
concat(str1, str2) <- Returns a single string consisting of str1 followed by str2. For example, concat("key", "board") returns "keyboard".reverse(str) <- Returns the reverse of the string str. For example, reverse("abcd") returns "dcba". Which of the following code segments can be used to store "noon" in the string variable word ?
word ← "on" word ← concat(reverse(word), word)
Consider the following code segment.x ← 25y ← 50z ← 75x ← yy ← zz ← xWhich of the variables have the value 50 after executing the code segment?
x and z only
Consider the following code segment, which uses the variables r, s, and t.r + 1 S+ 2 t < 3 r+S s+ t DISPLAY (r) DISPLAY (s) What is displayed as a result of running the code segment?
2 3
Consider the following code segment.a=10b=20c=30d=40x=20b=x+ba=x+1d=c+d/2DISPLAY aDISPLAY bDISPLAY cDISPLAY dWhat is displayed as a result of executing the code segment?
21 40 30 50
Consider the following code segment. x=23 z=x MOD y Which of the following initial values of the variable y would result in the variable z being set to 2 after the code segment is executed?
3
A student is creating an algorithm to display the distance between the numbers num1 and num2 on a number line. The following table shows the distance for several different values. Which of the following algorithms displays the correct distance for all possible values of num1 and num2 ?
Step 1: Subtract num1 from num2 and store the result in the variable diff. Step 2: Take the absolute value of diff and display the result.
A school library allows students to borrow laptops. A computer program is used to count the number of times a particular laptop has been borrowed from the library (borrows) and the number of times the same laptop has been returned to the library (returns). Which of the following indicate that a particular laptop is not currently borrowed? Select two answers.
The difference between borrows and returns is 0. The sum of borrows and returns is a positive even number.
The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following the most appropriate data type for isOpen?
boolean
The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ?
number
Three words are stored in the variables word1, word2, and word3. The values of the variables are to be updated as shown in the following table.(table)Which of the following code segments can be used to update the values of the variables as shown in the table?
temp ← word1 word1 ← word3 word3 ← temp