Font size
WorksheetsPython Programming Boot Camp I
Total questions: 100
Worksheet time: 33mins
Python is ___________ level programming language and is ___________.
High, compiled
High, interpreted
Low, compiled
Low, interpreted
A statement in programming
Expresses an action to be carried out
Always returns results like expressions
Rules controlling how components in a program are combined
An instruction to perform a task, usually one word
A block is
a statement including elements of a command
the structure and form of the code
source code that is grouped together
meaning assigned to symbols, characters and words
What symbol comes before a comment?
$
>>
#
!
An exception is
the structure of form of the code
the meaning of the characters and words in the code
the statement that is missing from the instructions
an event occurring during execution of a program which disrupts the flow of the program's instructions
Debugging is
how characters are arranged in a statement
detecting or removing errors from a program
removing viruses from a computer
the meaning of each of the characters and symbols in the program
What will be the output of the following code?
A) Greater
B) Smaller
C) Error
D) None
What will be the output of the following code?
A) Greater
B) Smaller
C) Equal
D) Error
What will be the output of the following code?
A) Yes
B) No
C) Error
D) None
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
Which of the following are true of Python dictionaries:
Dictionaries can be nested to any depth.
Dictionaries are accessed by key.
All the keys in a dictionary must be of the same type.
Dictionaries are mutable.
A dictionary can contain any object type except another dictionary.
Which of the following is not a valid way to define this dictionary in Python:
d = dict([
('foo', 100),
('bar', 200),
('baz', 300)
])
d = {}
d['foo'] = 100
d['bar'] = 200
d['baz'] = 300
d = dict(foo=100, bar=200, baz=300)
d = {'foo': 100, 'bar': 200, 'baz': 300}
d = { ('foo', 100), ('bar', 200), ('baz', 300) }
Suppose x is defined as follows:
x = [
'a',
'b',
{
'foo': 1,
'bar':
{
'x' : 10,
'y' : 20,
'z' : 30
},
'baz': 3
},
'c',
'd'
]
What is the expression involving x that accesses the value 30?
x[2]["bar"]["z"]
x[2]["bar"]
x["bar"]["z"]
x[2]["bar"]["z"][3]
What would be the output of the following code snippet?
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
d_items = a_dict.items()
print(d_items)
('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')
dict_items([('color'), ('fruit'), ('pet')])
[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]
dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])
Is python list mutable?
True
False
What is the primary function used to open a file in Python?
A. file()
B. open()
C. read()
D. write()
What does the write() method do?
A. Reads the entire file
B. Writes data to the file
C. Appends data to the file
D. Closes the file
Which of the following methods reads the entire content of a file?
What is the primary function used to open a file in Python?
A. file()
B. open()
C. read()
D. write()
Which mode is used to open a file for reading in Python?
A. r
B. w
C. a
D. b
What does the write() method do?
A. Reads the entire file
B. Writes data to the file
C. Appends data to the file
D. Closes the file
How do you close a file in Python?
A. file.end()
B. file.close()
C. file.quit()
D. file.stop()
Which of the following methods reads the entire content of a file?
What does the with statement do when working with files?
A. Closes the file automatically after the block
B. Opens multiple files simultaneously
C. Reads a file line by line
D. Writes to multiple files simultaneously
What mode is used to open a file for appending data?
A. r
B. w
C. a
D. b
What does the file.seek(0) method do?
A. Moves the cursor to the end of the file
B. Moves the cursor to the beginning of the file
C. Reads the first line of the file
D. Closes the file
Which of the following is a binary file mode?
A. rb
B. r
C. w
D. a
How do you open a file for both reading and writing in binary mode?
A. rb+
B. wb+
C. ab+
D. r+
What will file.readlines() return?
A. A string of all the contents
B. A list where each element is a line in the file
C. A tuple of file lines
D. An integer representing the number of lines
What is the default mode if none is specified when opening a file?
A. r
B. w
C. a
D. b
Which method can be used to write multiple lines to a file?
A. file.write_multiple()
B. file.writelines()
C. file.writemany()
D. file.write()
How can you check if a file is closed in Python?
A. file.closed()
B. file.isclosed()
C. file.closed
D. file.isclosed
Which of the following modes will overwrite the existing file content?
A. r
B. w
C. a
D. x
Which method is used to flush the internal buffer?
A. file.flush()
B. file.buffer()
C. file.empty()
D. file.clear()
Which method reads all lines and returns them as a list of strings?
How do you open a file for reading and writing, but not create if it does not exist?
A. r+
B. w+
C. a+
D. x+
What is the purpose of the file.truncate(size) method?
A. Removes the first size bytes from the file
B. Clears the file content
C. Changes the file size to size bytes
D. Deletes the file
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
Which of the following keyword is optional in Exception handling program
try
except
finally
else
Can one except block handle multiple exceptions?
Yes
No
May be
Insufficient information
The ZeroDivisionError may occur during which operation(s)?
Division
Modulo
Both
None
What is the output of the attached python code?
100
0
Zero Division Error Occurred
Another error will occur, program will "crash"
What will be the output of the following code?
A) 2 + 3
B) 5
C) "5"
D) Error
What will be the output of the following code?
A) 6
B) 3
C) 2
D) Error
What will be the output of the following code?
A) 4
B) 8
C) 16
D) Error
___________ are the arguments passed to a function in correct positional order.
Keyword arguments
Default arguments
Variable-length arguments
Required arguments
none of the above
what are methods??????
Blocks of code that are executed when called
code that does one specific thing really well
IHAVENOIDEA
None
What is a local copy of a remote repository called?
Branch
Origin
Clone
Master
The main objectives of Git are :
speed
data integrity
support for distributed non-linear workflows
All of the above
Git command . . . . used to give tags to the specified commit.
git checkout [branch name]
git show [commit]
git tag [commitID]
git rm [file]
Git is a . . . . Version Control tool.
Decentralized
Centralized
Which command creates an empty Git repository in the specified directory?
git reset
git log ..
git init
git init --bare
to move between desktops which key will you press?
win+ ctrl+left arrow
win+ctrl+right arrow
win+left arrow
win+right arrow
to minimize all apps press ____+___
win+m
esc+m
ctrl+Shift+m
esc+r
to open file explorer press__+___
win +i
win+q
win+e
win+l
to lock your PC press
win+L
win+i
win+r
win+q
Ctrl + X stands for
cut
copy
paste
select all
what does ctrl + Z do ?
Undo
Redo
cut
copy
What is the short cut for SAVE?
What is the shortcut for COPY?
What is the shortcut for PASTE?
What is the shortcut for UNDO?
Alt + U
Shift + U
Ctrl + Z
Ctrl + Y
What is the shortcut for REDO?
Alt + R
Shift + R
Ctrl + Y
Ctrl + Z
What is the shortcut for SELECT ALL?
Alt + A
Shift + A
Ctrl + S
Ctrl + A
What is the shortcut for OPEN?
Which programming language is known for making websites more interactive by adding elements such as animations, dropdown menus, and color-changing buttons?
C#
JavaScript
Python
Java
Which programming language is widely used in various fields such as scripting, web development, machine learning, data science, artificial intelligence, and robotics due to its simplicity and readability?
R
Kotlin
Python
Java
Which generation?
Machine Code - Low
Assembly Code - Low
High Level
Python is an example of a High Level programming language
True
False
Which level would create the easiest code for humans to understand?
Low
Assembly
High
Which level of a programming language is Assembly Code?
Low
High
Which level of a programming language is Machine Code?
Low
High
Which has integer data type?
Phone number
Zip code
HN
Number of students in the class
We can iterate over string
True
False
Which mathematical concept is fit to text data (e.g. words in documents)
Set
Bag
List
Tuple
There are 40 students in a classroom. We would like to get all students whose name starts with "A". Which looping is suitable?
For loop
While loop
Which data type is the best to store possible outcome of tossing a dice?
Tuple
List
Dictionary
We can insert the new item into tuple
True
False
You are in the car with traffic jammed at a junction. To cross that junction according to the traffic rules, which one is NOT applicable
While loop
Conditional Statement
For loop
You want to sampling 10 from 100 patients (One-by-One). Which one does NOT necessary in your code?
For loop
While loop
Conditional Statement
Set
Given a statement "All swan are white". To falsify this statement, you need to travel around the world and find at least one non-white swan. Which one is a indispensable command in your coding?
For loop
While loop
Conditional statement
Patients visit hospital everyday. You want to count for the "new patients" for each day. Which one is not necessary?
Set
While loop
For loop
Set difference
What is a recursive function in Python?
A function that calls itself
A function that returns a Boolean value
A function that performs mathematical operations
A function that has multiple return values
What is the purpose of the "return" statement in a function?
To end the execution of a function
To return a value from a function
To print output from a function
To define a local variable within a function
What is the purpose of the "return" statement in a function?
To end the execution of a function
To return a value from a function
To print output from a function
To define a local variable within a function
What is the scope of a variable defined inside a function?
Global scope
Local scope within the function
Both global and local scope
It is not possible to define variables inside a function
Can a Python function return more than one value simultaneously?
Yes
No
Only if the return values are of the same data type
Only if the return values are stored in a list or tuple
What is the output of the following code snippet?
def square_and_cube(x):
return x**2, x**3
result = square_and_cube(2)
print(result)
(4, 8)
[4, 8]
(4)
[4]
