2025 - C173 2025/2026 SCRIPTING AND PROGRAMMING -
FOUNDATIONS
What is an editor in programming?
a. A tool that compiles code
b. A program that allows you to write and modify code
c. A debugger for running programs
d. A version control system
Rationale: An editor provides syntax highlighting and editing features for source code.
What is a compiler?
a. A program that executes code line by line
b. A program that translates source code into an executable all at once
c. A library of reusable functions
d. A code formatter
Rationale: Compilers convert entire source files into machine code before execution.
What is an interpreter?
a. A compiler that optimizes code
b. A program that generates documentation
c. A program that executes source code one statement at a time
d. A syntax checker
Rationale: Interpreters parse and run code incrementally, without producing a standalone executable.
What is an operator?
a. A function that reads input
b. A keyword that declares variables
c. A symbol that takes one or more operands and performs a computation or comparison
d. A module import statement
Rationale: Operators like +, -, %, or == act on values to produce a result.
What is an expression?
a. A loop construct
b. Any code fragment that evaluates to a value
c. A comment line
d. A module import
Rationale: Expressions combine literals, variables, and operators to compute values.
How does a terminal expression differ from a non-terminal expression?
a. Terminal expressions contain loops; non-terminals do not
b. Terminal expressions are only in markup; non-terminals are in code
c. Terminal expressions cannot be simplified further; non-terminals can
,ESTUDYR
d. Terminal expressions declare variables; non-terminals do not
Rationale: In grammar, terminals are final tokens, whereas non-terminals expand into other symbols.
Which BNF grammar rule correctly describes a simple arithmetic expression?
a. <Expr> → <Expr> <Expr>
b. <Expr> → <Value> <Value>
c. <Expr> → <Expr> <Op> <Expr>
d. <Expr> → <Op> <Expr>
Rationale: An expression can be two subexpressions connected by an operator.
What is a variable?
a. A fixed constant in code
b. A data type definition
c. A name that refers to a value stored in memory
d. A code comment
Rationale: Variables bind identifiers to data values that can change.
How do you declare a string in Python?
a. myVar = 33
b. myVar = "hello"
c. myVar = True
d. myVar = [1, 2, 3]
Rationale: Strings in Python are enclosed in single or double quotes.
How do you declare an integer in Python?
a. myVar = "42"
b. myVar = False
c. myVar = 42
d. myVar = (42)
Rationale: Integers are represented without quotes or decimals.
How do you declare a boolean in Python?
a. myVar = 1
b. myVar = True
c. myVar = "True"
d. myVar = yes
Rationale: Boolean literals in Python are True or False (capitalized).
If your Python code doesn’t match language grammar, what error will you see?
a. RuntimeError
b. TypeError
c. SyntaxError
d. NameError
Rationale: Syntax errors occur when code structure violates Python’s grammar rules.
, ESTUDYR
How do you change the value of a variable in Python?
a. x == 9
b. x = 9
c. var x = 9
d. set x to 9
Rationale: The single equals sign (=) assigns a new value to the variable.
How do you concatenate two string variables a and b in Python?
a. a & b
b. concat(a,b)
c. a + b
d. a . b
Rationale: The + operator joins strings end-to-end.
What does indexing a string mean?
a. Sorting its characters
b. Accessing a single character by its position
c. Changing its case
d. Splitting it on whitespace
Rationale: name[0] retrieves the first character of name.
How do you slice "Python" to get "Pyt"?
a. name[0:3]
b. name[:2]
c. name[3:]
d. name[0:3]
Rationale: Slicing uses [start:end], including start up to end-1.
What does the + operator do with numbers?
a. Subtracts
b. Concatenates only strings
c. Adds two operands
d. Divides
Rationale: + sums numeric operands and concatenates strings.
What does the = operator do?
a. Compares values
b. Assigns the right-hand value to the left-hand variable
c. Adds two numbers
d. Comments out code
Rationale: Assignment = stores the value into the variable.
What does the * operator do in Python?
a. Exponentiation