wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Boot Camp I

Total questions: 100

Worksheet time: 33mins

Name
Class
Date
1.

Python is ___________ level programming language and is ___________.

a)

High, compiled

b)

High, interpreted

c)

Low, compiled

d)

Low, interpreted

2.

A statement in programming

a)

Expresses an action to be carried out

b)

Always returns results like expressions

c)

Rules controlling how components in a program are combined

d)

An instruction to perform a task, usually one word

3.

A block is

a)

a statement including elements of a command

b)

the structure and form of the code

c)

source code that is grouped together

d)

meaning assigned to symbols, characters and words

4.

What symbol comes before a comment?

a)

$

b)

>>

c)

#

d)

!

5.

An exception is

a)

the structure of form of the code

b)

the meaning of the characters and words in the code

c)

the statement that is missing from the instructions

d)

an event occurring during execution of a program which disrupts the flow of the program's instructions

6.

Debugging is

a)

how characters are arranged in a statement

b)

detecting or removing errors from a program

c)

removing viruses from a computer

d)

the meaning of each of the characters and symbols in the program

7.

What will be the output of the following code?

a)
  • A) Greater

b)
  • B) Smaller

c)
  • C) Error

d)
  • D) None

8.

What will be the output of the following code?

a)
  • A) Greater

b)
  • B) Smaller

c)
  • C) Equal

d)
  • D) Error

9.

What will be the output of the following code?

a)
  • A) Yes

b)
  • B) No

c)
  • C) Error

d)
  • D) None

10.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed

11.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

12.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

13.

Which of the following are true of Python dictionaries:

a)

Dictionaries can be nested to any depth.

b)

Dictionaries are accessed by key.

c)

All the keys in a dictionary must be of the same type.

d)

Dictionaries are mutable.

e)

A dictionary can contain any object type except another dictionary.

14.

Which of the following is not a valid way to define this dictionary in Python:

a)

d = dict([

('foo', 100),

('bar', 200),

('baz', 300)

])

b)

d = {}

d['foo'] = 100

d['bar'] = 200

d['baz'] = 300

c)

d = dict(foo=100, bar=200, baz=300)

d)

d = {'foo': 100, 'bar': 200, 'baz': 300}

e)

d = { ('foo', 100), ('bar', 200), ('baz', 300) }

15.

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?

a)

x[2]["bar"]["z"]

b)

x[2]["bar"]

c)

x["bar"]["z"]

d)

x[2]["bar"]["z"][3]

16.

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)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

17.

Is python list mutable?

a)

True

b)

False

18.

What is the primary function used to open a file in Python?

a)

A. file()

b)

B. open()

c)

C. read()

d)

D. write()

19.

What does the write() method do?

a)

A. Reads the entire file

b)

B. Writes data to the file

c)

C. Appends data to the file

d)

D. Closes the file

20.
  • Which of the following methods reads the entire content of a file?

a)
b)
  • B. file.readline()

c)
  • C. file.readlines()

d)
  • D. file.readfile()

21.

What is the primary function used to open a file in Python?

a)

A. file()

b)

B. open()

c)

C. read()

d)

D. write()

22.

Which mode is used to open a file for reading in Python?

a)

A. r

b)

B. w

c)

C. a

d)

D. b

23.

What does the write() method do?

a)

A. Reads the entire file

b)

B. Writes data to the file

c)

C. Appends data to the file

d)

D. Closes the file

24.

How do you close a file in Python?

a)

A. file.end()

b)

B. file.close()

c)

C. file.quit()

d)

D. file.stop()

25.
  • Which of the following methods reads the entire content of a file?

a)
b)
  • B. file.readline()

c)
  • C. file.readlines()

d)
  • D. file.readfile()

26.

What does the with statement do when working with files?

a)

A. Closes the file automatically after the block

b)

B. Opens multiple files simultaneously

c)

C. Reads a file line by line

d)

D. Writes to multiple files simultaneously

27.

What mode is used to open a file for appending data?

a)

A. r

b)

B. w

c)

C. a

d)

D. b

28.

Which method is used to read a single line from a file?

a)

A. file.read()

b)

B. file.readline()

c)

C. file.readlines()

d)

D. file.read_single()

29.

What does the file.seek(0) method do?

a)

A. Moves the cursor to the end of the file

b)

B. Moves the cursor to the beginning of the file

c)

C. Reads the first line of the file

d)

D. Closes the file

30.
  • Which of the following is a binary file mode?

a)
  • A. rb

b)
  • B. r

c)
  • C. w

d)
  • D. a

31.

How do you open a file for both reading and writing in binary mode?

a)

A. rb+

b)

B. wb+

c)

C. ab+

d)

D. r+

32.

What will file.readlines() return?

a)

A. A string of all the contents

b)

B. A list where each element is a line in the file

c)

C. A tuple of file lines

d)

D. An integer representing the number of lines

33.
  • What is the default mode if none is specified when opening a file?

a)
  • A. r

b)
  • B. w

c)
  • C. a

d)
  • D. b

34.

Which method can be used to write multiple lines to a file?

a)

A. file.write_multiple()

b)

B. file.writelines()

c)

C. file.writemany()

d)

D. file.write()

35.

How can you check if a file is closed in Python?

a)

A. file.closed()

b)

B. file.isclosed()

c)

C. file.closed

d)

D. file.isclosed

36.

Which of the following modes will overwrite the existing file content?

a)

A. r

b)

B. w

c)

C. a

d)

D. x

37.

Which method is used to flush the internal buffer?

a)

A. file.flush()

b)

B. file.buffer()

c)

C. file.empty()

d)

D. file.clear()

38.

Which method reads all lines and returns them as a list of strings?

a)

A. file.read()

b)

B. file.readline()

c)

C. file.reads()

d)

D. file.readlines()

39.
  • How do you open a file for reading and writing, but not create if it does not exist?

a)
  • A. r+

b)
  • B. w+

c)
  • C. a+

d)
  • D. x+

40.

What is the purpose of the file.truncate(size) method?

a)

A. Removes the first size bytes from the file

b)

B. Clears the file content

c)

C. Changes the file size to size bytes

d)

D. Deletes the file

41.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

42.

Which of the following keyword is optional in Exception handling program

a)

try

b)

except

c)

finally

d)

else

43.

Can one except block handle multiple exceptions?

a)

Yes

b)

No

c)

May be

d)

Insufficient information

44.

The ZeroDivisionError may occur during which operation(s)?

a)

Division

b)

Modulo

c)

Both

d)

None

45.

What is the output of the attached python code?

a)

100

b)

0

c)

Zero Division Error Occurred

d)

Another error will occur, program will "crash"

46.

What will be the output of the following code?

a)
  • A) 2 + 3

b)
  • B) 5

c)
  • C) "5"

d)
  • D) Error

47.

What will be the output of the following code?

a)
  • A) 6

b)
  • B) 3

c)
  • C) 2

d)
  • D) Error

48.

What will be the output of the following code?

a)
  • A) 4

b)
  • B) 8

c)
  • C) 16

d)
  • D) Error

49.

___________ are the arguments passed to a function in correct positional order.

a)

Keyword arguments

b)

Default arguments

c)

Variable-length arguments

d)

Required arguments

e)

none of the above

50.

what are methods??????

a)

Blocks of code that are executed when called

b)

code that does one specific thing really well

c)

IHAVENOIDEA

d)

None

51.

What is a local copy of a remote repository called?

a)

Branch

b)

Origin

c)

Clone

d)

Master

52.

The main objectives of Git are :

a)

speed

b)

data integrity

c)

support for distributed non-linear workflows

d)

All of the above

53.

Git command . . . . used to give tags to the specified commit.

a)

git checkout [branch name]

b)

git show [commit]

c)

git tag [commitID]

d)

git rm [file]

54.

Git is a . . . . Version Control tool.

a)

Decentralized

b)

Centralized

55.

Which command creates an empty Git repository in the specified directory?

a)

git reset

b)

git log ..

c)

git init

d)

git init --bare

56.
Which is Distributed version control system?
a)
cvs
b)
Perforce
c)
svn
d)
git
57.
What command lets you create a connection between a local and remote repository?
a)
git remote add origin
b)
git remote add new
c)
git remote new origin
d)
git remote origin
58.
Which of the following git command that downloads your repository from GitHub to your computer?
a)
git clone
b)
git commit
c)
git fork
d)
git push
59.

to move between desktops which key will you press?

a)

win+ ctrl+left arrow

b)

win+ctrl+right arrow

c)

win+left arrow

d)

win+right arrow

60.

to minimize all apps press ____+___

a)

win+m

b)

esc+m

c)

ctrl+Shift+m

d)

esc+r

61.

to open file explorer press__+___

a)

win +i

b)

win+q

c)

win+e

d)

win+l

62.

to lock your PC press

a)

win+L

b)

win+i

c)

win+r

d)

win+q

63.

Ctrl + X stands for

a)

cut

b)

copy

c)

paste

d)

select all

64.

what does ctrl + Z do ?

a)

Undo

b)

Redo

c)

cut

d)

copy

65.

What is the short cut for SAVE?

a)
Alt + S
b)
Shift + S
c)
Ctrl + A
d)
Ctrl + S
66.

What is the shortcut for COPY?

a)
Alt + C
b)
Shift + C
c)
Ctrl + C
d)
Ctrl + X
67.

What is the shortcut for PASTE?

a)
Shift + P
b)
Ctrl + V
c)
Ctrl + C
d)
Alt + P
68.

What is the shortcut for UNDO?

a)

Alt + U

b)

Shift + U

c)

Ctrl + Z

d)

Ctrl + Y

69.

What is the shortcut for REDO?

a)

Alt + R

b)

Shift + R

c)

Ctrl + Y

d)

Ctrl + Z

70.

What is the shortcut for SELECT ALL?

a)

Alt + A

b)

Shift + A

c)

Ctrl + S

d)

Ctrl + A

71.

What is the shortcut for OPEN?

a)
Alt + O
b)
Shift + O
c)
Ctrl + O
d)
Ctrl + P
72.

Which programming language is known for making websites more interactive by adding elements such as animations, dropdown menus, and color-changing buttons?

a)

C#

b)

JavaScript

c)

Python

d)

Java

73.

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?

a)

R

b)

Kotlin

c)

Python

d)

Java

74.
What does IDE stand for?
a)
Integrated Debugging Equipment
b)
Integrated Debugging Environment
c)
Integrated Development Equipment
d)
Integrated Development Environment
75.
A person who writes code and communicates instructions to a computer.
a)
Code
b)
Programmer
c)
Command
d)
Program
76.

Which generation?

a)

Machine Code - Low

b)

Assembly Code - Low

c)

High Level

77.
A disadvantage of programming in High Level is
a)
A lot of code must be translated before it can be executed
b)
Difficult to debug
c)
High level of technical skill is required
78.
An advantage of programming in High Level is
a)
Easier for us to understand
b)
Useful for device drivers
c)
Programs execute faster than other generations
79.

Python is an example of a High Level programming language

a)

True

b)

False

80.

Which level would create the easiest code for humans to understand?

a)

Low

b)

Assembly

c)

High

81.

Which level of a programming language is Assembly Code?

a)

Low

b)

High

82.

Which level of a programming language is Machine Code?

a)

Low

b)

High

83.
Example of First Generation Programming Language
a)
COBOL
b)
Machine Language
c)
C++
84.
Which generation would create the easiest code for humans to understand?
a)
1st Generation (Low)
b)
2nd Generation (Low)
c)
3rd Generation (High)
85.

Which has integer data type?

a)

Phone number

b)

Zip code

c)

HN

d)

Number of students in the class

86.

We can iterate over string

a)

True

b)

False

87.

Which mathematical concept is fit to text data (e.g. words in documents)

a)

Set

b)

Bag

c)

List

d)

Tuple

88.

There are 40 students in a classroom. We would like to get all students whose name starts with "A". Which looping is suitable?

a)

For loop

b)

While loop

89.

Which data type is the best to store possible outcome of tossing a dice?

a)

Tuple

b)

List

c)

Dictionary

90.

We can insert the new item into tuple

a)

True

b)

False

91.

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

a)

While loop

b)

Conditional Statement

c)

For loop

92.

You want to sampling 10 from 100 patients (One-by-One). Which one does NOT necessary in your code?

a)

For loop

b)

While loop

c)

Conditional Statement

d)

Set

93.

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?

a)

For loop

b)

While loop

c)

Conditional statement

94.

Patients visit hospital everyday. You want to count for the "new patients" for each day. Which one is not necessary?

a)

Set

b)

While loop

c)

For loop

d)

Set difference

95.

What is a recursive function in Python?

a)

A function that calls itself

b)

A function that returns a Boolean value

c)

A function that performs mathematical operations

d)

A function that has multiple return values

96.

What is the purpose of the "return" statement in a function?

a)

To end the execution of a function

b)

To return a value from a function

c)

To print output from a function

d)

To define a local variable within a function

97.

What is the purpose of the "return" statement in a function?

a)

To end the execution of a function

b)

To return a value from a function

c)

To print output from a function

d)

To define a local variable within a function

98.

What is the scope of a variable defined inside a function?

a)

Global scope

b)

Local scope within the function

c)

Both global and local scope

d)

It is not possible to define variables inside a function

99.

Can a Python function return more than one value simultaneously?

a)

Yes

b)

No

c)

Only if the return values are of the same data type

d)

Only if the return values are stored in a list or tuple

100.

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)

   

a)

(4, 8)

b)

[4, 8]

c)

(4)

d)

[4]