1/50
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the five major components of a computer system?
CPU, main memory, secondary storage, input devices, and output devices
What is the purpose of ASCII?
ASCII (American Standard Code for Information Interchange) is used to represent characters such as english letters as numeric codes, facilitating text storage and communication between computers.
What is a "magic number" in programming?
A magic number is an unexplained value that appears directly in a program's code, often representing some important quantity but lacking context or documentation.
What is a sentinel value, and how is it used?
A sentinel value is a special value used to mark the end of a sequence of data. It is distinct from the actual data values. Sentinels are used to control loops that process input.
What are list comprehensions?
List comprehensions provide a concise way to create new lists based on existing lists or other iterables.
What are the advantages and disadvantages of high-level programming languages compared to low-level languages like assembly?
High-level languages are easier to read and write but slower to execute than low-level languages.
What is the primary difference between a compiler and an interpreter?
A compiler translates the entire program into machine code before execution, while an interpreter translates the program line by line.
How do you format numeric output in Python?
Use f-strings
or format()
to control the number of decimals, padding, etc.
What are named constants, and why are they useful?
Variables with fixed values that are defined and cannot be changed during execution.
What are relational operators, and how are they used in decision-making?
Relational operators compare values to determine true or false (e.g., ==
, >
, <
)
How do logical operators (and
, or
, not
) create compound Boolean expressions?
and
and or
combine multiple conditions, while not
inverts a condition.
What is a Boolean variable, and how is it used as a flag in programs?
A Boolean variable can store True
or False
values and is used to control program flow or indicate state.
Explain the difference between condition-controlled loops (while
) and count-controlled loops (for
). Provide examples of when each type is appropriate.
while
loop: Repeats as long as a condition is true. Appropriate when the number of iterations is unknown or based on dynamic conditions.
for
loop: Repeats a set number of times, often iterating over a sequence like a list or range. Appropriate when the number of iterations is known in advance.
Explain the importance of input validation and how to implement it using loops.
Input validation ensures that the data entered by the user is of the correct type and meets specified criteria. It can be implemented using loops to repeatedly ask the user for input until valid data is provided.
What are functions, and why are they important in programming?
Functions are blocks of code that perform a specific task and can be reused. They help make code more modular, organized, and easier to maintain.
When using the // operator to perform division, what happens if the result is a negative number?
The result is rounded away from zero to the nearest integer.
When using the // operator to perform division, what happens if the result is a positive number?
The result is truncated (meaning, the fractional part is thrown away).
What will be displayed after the following code is executed?
def pass_it(x, y):
z = x*y
result = get_result(z)
return(result)
def get_result(number):
z = number + 2
return(z)
num1 = 3
num2 = 4
answer = pass_it(num1, num2)
print(answer)
14
Which of the following will display 20%?
print(f'{0.2:.0%}')
What is the output of the following code?
val = 123.456789
print(f'{val:.3f}')
123.457
The encoding technique used to store negative numbers in the computer's memory is called
two’s complement
What is the output of the following statement?
print('One'
'Two'
'Three')
OneTwoThree
What is the decimal value of the following binary number?
10011101
157
The decision structure that has two possible paths of execution is known as
Dual alternative
What will be displayed after the following code is executed?
total = 0
for count in range(1,4):
total += count
print(total)
6
Which of the following is not a major component of a typical computer system?
CPU
Operating system
Main memory
Secondary storage devices
Operating System
What does the following statement mean?
num1, num2 = get_num()
The function get_num() is expected to return a value for num1 and for num2.
What will be the output after the following code is executed?
def pass_it(x, y):
z = x , ", " , y
num1 = 4
num2 = 8
answer = pass_it(num1, num2)
print(answer)
None
What is the difference between the remove method in a list and using the del statement?
The remove method searches for and removes an element containing a specific value. The del statement removes an element at a specific index.
Assume the following statement appears in a program.
names = []
Why is the append function used instead of names[0] to add to the list at index 0?
This is because the index 0 does not exist. If you tried names[0], an error would occur.
What does the index function in lists do?
It searches for an item in the list and returns the index of the first element containing that item.
What does the reverse function in lists do?
It reverses the order of items in the list.
Write a set of nested loops that display the contents of the numbers list.
numbers = [[1,2], [10,20], [100,200], [1000,2000]]
for r in range(4):
for c in range(2):
print(numbers[r][c])
Why do tuples exist?
Processing a tuple is faster than processing a list so it’s more helpful when processing large amounts of data.
Tuples are safe because the contents cannot be modified after being created.
What is a program?
A program is a set of instructions that a computer follows to perform a task
What are the five major components of a computer system?
CPU, main memory, secondary storage devices, input devices, output devices
What does an assembler do?
It translates assembly language to machine language.
What part of the computer serves as a work area to store a program and its data while the program is running?
Main memory
What part of the computer stores data for a long period of time, even when there is no power to the computer?
Secondary storage
What fundamental set of programs control the internal operations of the computer’s hardware?
Operating System
What is a program that performs a specialized task such as a virus scanner?
Utility Program
In what numbering system are all numeric values written as sequences of 0s and 1s?
Binary numbering system
What does digital data mean?
Data that is stored in binary format
What is a digital device?
Any device that works with binary data
When a CPU executes the instructions in a program, it is engaged in what process?
Fetch-decode-execute cycle
What is assembly language?
It is a language that uses short words known as mnemonics for instructions.
What are the steps in the program development cycle?
Design the program
Write the code
Correct syntax errors
Test the program
Correct logic errors
The % symbol is the remainder operator, also known as _______ operator.
modulus, mod
A(n) _________ character is a special character that is preceded by a backslash (\), appearing inside a string literal.
escape
The __________ specifier is a special set of characters that specify how a value should be formatted.
formatting
In the expression 12.45 + 3.6, the values to the right and left of the + symbol are the
operands