stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
SS25 Python Midterm Review- Davis Flashcards | StudBud
Explore
/
SS25 Python Midterm Review- Davis
SS25 Python Midterm Review- Davis
143 terms
·
StudBud Administration
·
76 plays
Imported from external platform
Flashcards
143 cards
F
Practice quiz
P
Host live
L
Questions
143
Answers
1
How do you terminate a loop prematurely in Python?
By using the stop statement
By using the terminate statement
By using the exit statement
By using the break statement
2
_______ is the code in natural language mixed with some program code
Pseudocode
Python program
A Python statement
A flowchart diagram
3
A Python line comment begins with ________.
$$
//
#
/*
4
What is the type for object 5.6?
str
float
int
5
How do you add a new key-value pair to a dictionary in Python?
Using assignment
Using the append() method
Using the add() method
Using the insert() method
6
Which of the following is equivalent to x != y?
x > y and x < y
x >= y or| x <= y
not (x == y)
x > y or x < y
7
Why is Indentation required in python?
Code Readibilty
Easier to read
To determine the scope
It looks nice
8
How do you access the attributes or methods of an object in Python?
Using curly braces
Using dot notation
Using parentheses
Using square brackets
9
Python is a dynamically typed, object-oriented, compiled language.
True
False
10
What is the default mode for opening a file in Python's open() function if no mode is specified?
read
write
append
all of them
11
To generate a random integer between 0 and 5, use ________________.
random.randrange(0, 5)
random.randint(0, 5)
random.randrange(0, 6)
random.randint(0, 6)
12
What is the output of the following code?x = 0if x < 4: x = x + 1print("x is", x)
1
0
2
4
13
What is the correct way to close a file object named file in Python?
close(file)
file.close()
close_file(file)
file.closeFile()
14
Which of the following is a valid identifier/variable name?
max_radius
mile
9X
$343
15
A function in Python can return multiple values
True
False
16
What is a tuple in Python?
A data structure similar to a list but immutable
A collection with ( )
A collection with { }
A collection of key-value pairs
17
How do you call a function named my_function in Python?
execute my_function()
call my_function()
my_function()
function my_function()
18
What happens to a mutable object passed to a function by reference in Python?
The function receives a reference to the object's memory location
The object's memory location is modified within the function
The function receives a copy of the object's value
The object's value is directly modified within the function
19
How can you convert a string to an integer in Python?
bool()
int()
str()
float()
20
What function do you use to read a string?
enter("Enter a string")
eval(input("Enter a string"))
eval(enter("Enter a string"))
input("Enter a string")
21
Analyze the following code:even = Falseif even = True: print("It is even!")
The program has a syntax error in line 2
The program runs, but displays nothing.
The program has a syntax error in line 1 (even = False)
The program runs and displays It is even!.
22
Which of the following statements about tuples in Python is true?
Tuples are created using square brackets [].
Tuples are mutable, meaning their elements can be changed after creation.
Tuples can only contain 1 data type
Tuples are ordered collections of elements, similar to lists.
23
Which function is used to write data to a file in Python?
print()
write()
output()
fwrite()
24
Which of these is NOT a common programming error in Python?
Spelling Error
Runtime Error
Syntax Error
Logic Error
25
Lists in Python are immutable ?
False
True
26
What does the with statement provide when working with files in Python?
File renaming
Automatic file closure
Exception handling
File creation
27
An identifier cannot be a keyword?
False
True
28
What is an attribute in Python?
A reserved word that cannot be used as an identifier.
A value associated with an object which is accessed using dot notation.
A type of loop used to iterate over elements in a sequence.
A type of function used to define classes.
29
____________ is a device to connect a computer to a local area network (LAN)
NIC
Cable modem
Regular modem
DSL
30
In Python, you can use both single and double quotes to create strings.
True
False
31
How do you append data to an existing file in Python?
Use append() function
Open the file in read mode and use write()
Open the file in write mode and use write()
Open the file in append mode and use write()
32
What is the correct syntax to write a decision structure for multiple conditions in Python?
if-else
if elif else
elif
switch-case
33
How do you convert a string "123" to an integer in Python?
int("123")
str("123")
float("123")
cast("123")
34
Analyze the following code.even = Falseif even: print("It is even!")
The code displays It is even!
The code is wrong. You should replace if even: with if even == True:
The code is wrong. You should replace if even: with if even = True:
The code displays nothing
35
Which of the following statements is correct?
s = "Chapter " + 1
s = "Chapter " + str(1)
36
What keyword is used to define a function in Python?
def
function
func
define
37
How do you open a file named "example.txt" in Python for reading?
open("example.txt", "r")
open_file("example.txt", "read")
open("example.txt", "read")
file_open("example.txt", "r")
38
2 ** 3.0 evaluates to __________.
8.0
9.0
8
9
39
What is a dictionary in Python?
A collection of elements presented as key-pair
A type of loop used for iteration
A built-in function for mathematical operations
A data structure used for sorting elements in ascending order
40
What is the
%
sign used for in Math in Python?
Modulo operator to calculate remainder.
Percentage sign to represent fractions.
Another way to have division in Python.
Percentage sign to calculate what percent is the number of another number.
41
What is a module in Python?
A file containing Python code that can be reused in other Python files
A built-in function for mathematical operations
A named block of code that performs a specific task
A data type used for storing text
42
What will be the value of the following Python expression? 4 + 3 % 5
7
4
2
1
43
What is a function in Python?
A data type used for storing text
A built-in module for mathematical operations
A named block of code that performs a specific task
A keyword used for defining loops
44
What is a statement in Python?
A function used to print output to the console
A line of code that performs an action
A comment used to explain code
A block of code that performs a specific task
45
In Python, a string literal is enclosed in __________.
double-quotes
brackets
braces
single-quotes
parentheses
46
The word True is ________.
a Boolean literal
a Python keyword
same as value 1
same as value 0
47
When should you use global variables in Python?
When you want to improve code encapsulation and maintainability
When you want to limit the visibility of variables within a function
When you need to share data across multiple functions or modules
When you want to avoid potential naming conflicts
48
If a number is too large to be stored in memory, it _____________.
cause underflow
cannot happen in Python
causes no error
causes overflow
49
You can place the line symbol __ at the end of a line to tell the interpreter that the statement is continued
/
#
\
*
50
How do you add a new key-value pair to a dictionary in Python?
By using the add() method
By using square brackets [new_key] = value
By using the insert() method
By using the append() method
51
To run python script file named t.py, use the command ________.
go python t.py
execute python t.py
run python t.py
python t.py
52
A Python paragraph comment uses the style ________.
// comments //
/# comments #/
/* comments */
''' comments '''
53
What will the following Python code output? x = 5 y = 10 print(x + y)
5 + 10
15
10 + 5
510
54
To run python script file named t.py, use the command ________.
run python t.py
go python t.py
python t.py
execute python t.py
55
Python syntax is case-sensitive.
False
True
56
What is the result of 45 / 4?
11
12
11.25
10
57
What is false about Python?
multi-paradigm programming language
Interoperability
Rich platform/ecosystem
Statically type
58
What will be the output of print("Python"[::-1])?
Python
Error
nohtyP
Py
59
What is the process of creating an instance of a class called in Python?
Instantiation
Execution
Inheritance
Definition
60
How do you add a single-line comment in Python?
/* This is a comment */
-- This is a comment
# This is a comment
// This is a comment
61
What is a declaration in python?
A loop used for iteration
A built-in function for mathematical operations
A conditional statement for decision making
A statement that defines a variable or function
62
Which of the following statements about variables in Python is true?
Variables can change types after they have been set.
Variables are used to store and manipulate data in memory.
Variables can only store numeric values.
Variables must be explicitly declared before use.
63
Which of the following is a valid variable name in Python?
variable-name
1variable
variable name
variable_name
64
What function is used to open a file in Python?
read()
open()
file_open()
fopen()
65
___________ translates high-level language program into machine language program.
Operating System
CPU
An assembler
A compiler
66
Data in python are objects
True
False
67
Which keyword is used to define a class in Python?
obj
def
struct
class
68
What is the syntax for a while loop in Python?
while loop_condition:
while (loop_condition):
while {loop_condition}:
while [loop_condition ]:
69
What will happen if you divide by zero in Python?
A runtime error
A syntax error
Nothing will happen
The program will print 0
70
In the expression 45 / 4, the values on the left and right of the / symbol are called ____.
operands
operators
parameters
arguments
71
________ is the physical aspect of the computer that can be seen.
Software
Application Program
Hardware
Operating System
72
What are the values of the following Python expressions?
64, 64, 64
512, 64, 512
512, 512, 512
64, 512, 64
73
Is pow(a, b) the same as a ** b?
True
False
74
In Python, how do you typically define a getter method for a class attribute "name"?
def get_name(self):
def name():
def get_name():
def name(self):
75
What does the "import" keyword do in Python?
Loads the module into memory
Executes the code inside the specified module
Defines a new module
Makes functions and variables from one module available in the current file
76
How do you create an empty tuple in Python?
empty_tuple = ()
empty_tuple = []
empty_tuple = None
empty_tuple = {}
77
How do you give value to a variable in python?
Using the equals sign (=)
Using the colon (:) followed by the value
Using the keyword "assign"
Using parentheses ()
78
How do you write a single-line comment in Python?
/* Comment */
// Comment
# Comment
<!-- Comment -->
79
One byte has ________ bits.
12
4
8
16
80
What is the syntax for a for loop in Python?
for condition:
for (condition):
for variable from sequence:
for variable in sequence:
81
What is a class in Python?
A function that returns a value.
A built-in data type.
A module that can be imported.
A blueprint for creating objects.
82
Provide the output
just right
too hot
too hot too cold just right
too cold
83
What is the result of evaluating 2 + 2 ** 3 / 2?
4
4.0
6.0
6
84
Which of the following expression results in a value 1?
25 % 5
15 % 4
2 % 1
37 % 6
85
Which of the following is the correct expression of character 4?
'4'
4
All of these
"4"
86
In Python, strings are immutable.
True
False
87
is this valid Python Code
Lists can only be one data type
You must define 3 separate lists
This is valid
Tuples can't be in a list
88
Which of the following is true about function arguments in Python?
They can only be of a specific data type
They are optional and can be omitted in function calls
They provide values to parameters when calling a function
They are required and must be specified in function definitions
89
The time.time() returns ________________ .
the current time in milliseconds since midnight.
the current time in milliseconds.
the current time.
the current time in milliseconds since midnight, January 1, 1970 GMT
90
Which statement about Python is FALSE?
Python is case-sensitive
Python supports multiple programming paradigms
All variables must be declared before use
Python uses indentation for blocks
91
What does the self keyword represent in Python class methods?
It refers to the current class instance
It is a reserved keyword for private variables
It is used for conditional statements within the method
It is used for typecasting within the method
92
How do you define a class in Python?
function MyClass:
class MyClass[]:
class MyClass:
def MyClass:
93
__________ is the brain of a computer.
Disk
CPU
Memory
Hardware
94
What will be displayed by the following code?x, y = 1, 2x, y = y, xprint(x, y)
2 2
2 1
1 2
1 1
95
Which of the following is true about the while loop in Python?
It is more suitable for iterating over a fixed number of elements
It repeats until a certain condition evaluates to False
It is less efficient compared to the for loop
It always executes its body at least once
96
Given |x - 2| <= 4, Which of the following is true?
x - 2 <= 4 or x - 2 >= -4
x - 2 <= 4 and x - 2 >= 4
x - 2 <= 4 and x - 2 > -4
x - 2 <= 4 and x - 2 >= -4
97
In Python, how are primitive data types (e.g., integers, floats) passed to functions?
It depends on the function signature
It depends on the size of the data type
By reference
By value
98
Which of the following functions return 4.
round(3.9)
round(3.4)
int(3.4)
int(3.9)
99
What is Python Bytecode?
Machine language of Python code
Intermediate language of Python code
100
What is the Python Virtual Machine (PVM)?
A hardware device that runs Python code.
A tool that converts Python code into Java bytecode.
A software component that interprets Python to bytecode.
An integrated development environment (IDE) for writing Python code.
101
To add a value 1 to variable x, you write
x += 1
1 + x = x
x = x + 1
x := 1
x = 1 + x
102
Which symbol is used for comments in Python?
@
//
*
#
103
The format function returns _______.
str
int
float
104
In Python, a string literal is enclosed in __________.
brackets
double-quotes
single-quotes
braces
parentheses
105
What will be the output of the following Python code?
8
5
12
4
106
What will be displayed by the following code?ch = 'F'if ch >= 'A' and ch <= 'Z': print(ch)
f
Nothing
F f
F
107
How do you access elements in a tuple in Python?
By using parentheses (index)
By using square brackets [index]
By using curly braces {index}
By using angle brackets <index>
108
What is the purpose of the continue statement in Python?
To restart the loop from the beginning
To terminate the loop prematurely
To exit the loop completely
Skip the rest of the code block and continue the next iteration of the loop
109
Which of these is not a valid comment in Python?
#Single line comment
""" Multi-line comment """
/* C-style comment */ ✓
'''Another multi-line comment'''
110
What is a block in Python
Group of statements in a program/script
Code indented differently
Instructions you type in editor
Code surrounded by { } braces
111
What function is used to get user input in Python?
read()
getInput()
scan()
input()
112
____________ are instructions to the computer.
Software
Keyboards
Program
Hardware
113
What will be displayed by the following code?print("A", end = ' ')print("B", end = ' ')print("C", end = ' ')
A B C
A, B, C will be displayed on four lines
ABC
A, B, C
114
The __________ function immediately terminates the program.
sys.exit()
sys.halt()
sys.stop()
sys.terminate()
115
What is the primary advantage of using modules in Python?
They speed up the execution of Python programs
They allow for code reuse and organization
They improve code readability
They automatically handle memory management
116
What is the purpose of the with open statement in Python?
To ensure proper handling closing the file when done
To open a file and return its contents
To create a new file
To delete a file
117
Which of the following is true about dictionary values in Python?
Values can be mutable objects like lists
All of the above
Values can be accessed using integer indices
Values must be unique within the dictionary
118
Which of the following is NOT a valid Python variable name?
my_var
_hidden
totalAmount
1st_place
119
Python does
not
execute comments
True
False
120
True or False: Python use { } to indicate code blocks
False
True
121
What happens to a variable passed to a function by value in Python?
The variable's memory location is modified within the function
The function receives a reference to the variable's memory location
The function receives a copy of the variable's value
The variable's value is directly modified within the function
122
What type of programming language is Python?
Compiled language
Machine language
Assembly language
Interpreted language
123
What is the difference between = and == in Python?
= is for assignment, == is for comparison
They are interchangeable
= is faster than ==
== is for assignment, = is for comparison
124
The expression "Good " + 1 + 2 + 3 evaluates to ________.
Good 123
Illegal expression
Good6
Good123
125
Will print(chr(4)) display 4?
True
False
126
Which function can you use to generate a random number in Python?
random()
math.random()
randint()
random.randint()
127
What does the input() function return in Python?
Integer
Boolean
Float
String
128
A ___________ error does not cause the program to abort, but produces incorrect results.
logic
Runtime
All of these
Synatx
129
In Python, which module provides access to mathematical functions like sqrt() and pi?
mathematics
numpy
math
calculator
130
Python only accepts ' ' single quote for String
True
False
131
What method is used to add an item to a list in Python?
add()
push()
insert()
append()
132
Which of the following data types are passed by reference in Python?
Tuples
Strings
List
Integers
133
In Python, a string literal is enclosed in __________.
braces
double-quotes
brackets
single-quotes
parentheses
134
Python reads
variable_name
and
variableName
as the
same
variable
True
False
135
A Python Dictionary uses ________ to access a value
elements
names
indexes
Keys
136
What is the value of the following expression?True or True and False
False
True
137
To add number to sum, you write (Note: Python is case-sensitive)
sum = Number + sum
sum = sum + number
number += sum
sum += number
number = sum + number
138
To format a number x to 3 digits after the decimal point, use _______.
format("5.3f", x)
format(x, "5.4f")
format("5.3f", x)
format(x, "5.3f")
139
What will be the output of the following Python code?
2
None
1
Error
140
Which of these is not a valid numeric type in Python?
decimal
character
int
float
141
Which operator is used for exponentiation in Python?
pow
**
^
^^
142
Which of the following is NOT a valid variable name in Python?
camelCase
my_variable
_hidden
2names ✓
143
How do you import a module named my_module in Python?
module my_module
import my_module
load my_module
use my_module