wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basic Exam #1

Total questions: 81

Worksheet time: 1hrs 1mins

Name
Class
Date
1.

Empty curly braces in an assignment statement will create which type of data structure?

(s = {})

a)

List

b)

Dictionary

c)

Stack

d)

Set

2.

Which is not true about sets?

a)

The .pop() method removes elements

b)

They are unordered

c)

Each element is unique

3.

Which data structure stores key/value pairs?

a)

Sets

b)

Stacks

c)

Lists

d)

Dictionaries

4.

Each key/value pair in a dictionary is separated by this symbol:

a)

/

b)

,

c)

:

d)

;

5.

Which data structure is exponentially more efficient than the others?

a)

List

b)

Set

c)

Tuple

d)

Hash Map

6.

Choose all of the following which are built in data types in Python

a)

dict

b)

list

c)

set

d)

tuple

7.

A dictionary is an example of a sequence ...

a)

True

b)

False

8.

Which code segment when inserted in the blank sets the "Year" from 2006 to 2008?

birthday = {

"Month": "January",

"Day": "01",

"Year":2006

}

__________________________________

OUTPUT: 2008

a)

birthday["Year"]=2008

b)

birthday[Year]=2008

c)

birthday [2008]

d)

birthday[2006]=2008

9.

What will this code do?

birthday = {

"Month": "January",

"Day": "01",

"Year":2006

}

for x in birthday:

print(x)

a)

Prints all the key names in the dictionary

b)

print all the key and value pairs is the dictionary

10.

The dictionary dnry is initialized as follows:

dnry = {"L": 8, "W": 5, "H": 11}

Which statement would evaluate to 5?

a)

dnry[1]

b)

dnry["W"]

c)

dnry["5"]

d)

dnry[2]

11.
Look at this code, how many times will it loop?
a)
50
b)
90
c)
0
d)
4
12.
What is another way of writing the following code? 
Score = Score + 1 
a)
Score.add(1)
b)
score + 1
c)
Score + Score
d)
Score += 1
13.
What are the two main types of loops that we have learned about in Python?
a)
IF Function & Variables
b)
FOR and WHILE Loops
c)
Forever and Fixed Loop
d)
Data Types and Numbers
14.
What is the word used to describe repetition in programming?
a)
Sequence
b)
Selection
c)
Iteration
d)
Coding
15.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

16.

for i in 100 :

print ( i )

a)

Syntax error

b)

prints numbers 0 to 100

c)

prints numbers 1 to 100

d)

prints numbers 0 to 99

e)

prints numbers 1 to 99

17.

Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.

a)

while loop

b)

for loop

c)

nested loop

d)

infinite loop

18.

Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

a)

while loop

b)

for loop

c)

nested loop

d)

infinite loop

19.

What does the code print?

a)

10

7

4

1

Done

b)

10

9

8

7

6

5

4

3

2

1

Done

c)

Done

d)

10

7

4

1

-2

-5

... and more, running infinitely.

20.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
21.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
22.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
23.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
24.

An example of Python code that creates a variable and assigns it to the string "Hello!"

a)

goodbye = "HAVE A GREAT DAY!"print(goodbye)

b)

welcome = "Hello!"

c)

"Today I had \"pizza"\ for lunch"

d)

print("Hello!" * 3)

25.

A: Strings can be changed during execution

B. Strings can be enclosed within single, double or even triple quotes

C. Strings are immutable

a)

A,B & C are True

b)

A,B are True but C is False

c)

B, C are True but A is False

d)

A,C are True but B is False

26.
For strings, the + operator represents 
a)
Concatenation
b)
Addition
c)
Appending
d)
Recantation 
27.

print(3*'hi')

a)

3hi

b)

3*hi

c)

hihihi

d)

Error

28.

print('e' in 'silence')

a)

1

b)

2

c)

True

d)

False

29.

What is the output of the following code?

a)

5

b)

Error

c)

2

d)

1

30.

" "

a)

String

b)

Integer

c)

Float

d)

Number

31.

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

32.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

33.

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"

34.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

35.

For tuples and list which is correct?

a)

List and tuples both are mutable.

b)

List is mutable whereas tuples are immutable.

c)

List and tuples both are immutable.

d)

List is immutable whereas tuples are mutable

36.

Which is a correctly declared tuple?

a)

a = ("orange", "yellow", "red")

b)

a = "orange", "yellow", "red"

c)

a = ["orange", "yellow", "red"]

d)

a = "orangeyellowred"

37.

Can you have an empty tuple z = () or an empty string w = []?

a)

yes

b)

no

38.

If L1=[2,4,8,16], L2=[32,64] what is L1+L2

a)

[2,4,8,16,32,64]

b)

[2,4,8,16][32,64]

c)

[2,4,8,16],[32,64]

d)

None of the above

39.

Suppose list1 is [1, 3, 2], What is list1 * 2 ?

a)

[2, 6, 4].

b)

[1, 3, 2, 1, 3]

c)

[1, 3, 2, 1, 3, 2]

d)

[1, 3, 2, 3, 2, 1]

40.

Match the following

a)

Unable to change.

1.

Immutable

b)

A particular way of organizing data in our programs.

2.

Data Structure

c)

A heterogenous, immutable data type that stores an ordered sequence of things.

3.

Tuple

d)

A heterogenous, mutable data type that stores an ordered sequence of things.

4.

List

e)

Add a particular item to the end of a list.

5.

append()

41.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
42.
What will the lines of code print?
a)
A
b)
B C
c)
A B C
d)
A C
43.
What will the following lines of code print?
a)
A
b)
B C
c)
A C
d)
Nothing, it will return an error.
44.
Which statement will check to see if a is equal to b?
a)
if a == b
b)
if a = b:
c)
if a != b:
d)
if a == b:
45.

Pieces of code that only run "under certain conditions":

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

46.

If you want to test more than one condition (chained condition), what do you use after if statement?

a)

elif

b)

else

c)

ifif

d)

else if

47.

‘If’ is a decision making statement

a)

TRUE

b)

FALSE

48.

Which of the following conditions tell me to sleep if my alarm did not go off (alarm = False) and I’m tired (tired = True)?

Both alarm and tired default assignment is True.

a)

b)

c)

d)

49.

How can you check if a value is NOT equal to a specific value in Python's if statement?

a)

Use the != operator

b)

Use the == operator

c)

Use the <> operator

d)

Use the <= operator

50.

What will print when this program is executed?

a)

You need an umbrella.

b)

You do not need an umbrella.

c)

True

d)

False

e)

Nothing will print

51.

What symbol is used in python to assign values to a variable?

a)

:

b)

*

c)

=

d)

==

52.

What is the correct name for this symbol?


==

a)

Assignment

b)

Equal to

c)

Greater than

d)

Less than

53.

x = 10

y = 10


print(x != y)

a)

True

b)

False

54.

x = 5

y = 3


print(x == y)

a)

True

b)

False

55.

What is this symbol called? (*)

a)

star

b)

asterisk

c)

apostrophe

d)

multiplication

56.

The result of 10%2 will be :

a)

1

b)

5

c)

2

d)

0

57.

Click all comparison operators

a)

!=

b)

*=

c)

==

d)

>=

e)

=

58.

Click all arithmetic operators

a)

**

b)

=

c)

+=

d)

-

e)

%

59.

An expression is

a)

A set of steps for performing a task, like a recipe.

b)

An ordered list of values or objects.

c)

To combine two strings of text into a single string.

d)

Any valid set of values, variables, operators, and functions that produces a value or result.

60.

Can you add 2.6 to "Cat"?

a)

Yes! I'll demonstrate on the board!

b)

No. You're probably nuts for thinking this.

61.

Please select all floating point numbers:

a)

1.444

b)

34567

c)

777.980

d)

32.0

e)

21

62.

What data type would store the value: True

a)

Boolean

b)

String

c)

Integer

d)

Float

63.

"89 / 90"

a)

String

b)

Integer

c)

Float

d)

Number

64.

What is the data type of ["Sunday","Monday","Tuesday"]

a)

List

b)

String

c)

Numeric

d)

Tuple

65.

Which of the following correctly stores 'price' as a decimal number?

a)

price = int ( input ("Price: ")

b)

price = str( input ("Price: ")

c)

price = float ( input ("Price: ")

d)

price = input ("Price: ")

66.

Which is the correct way to declare 3 variables, 'a' , 'b', 'c' to 1?

a)

a = b = c = 1

b)

a,b,c = 1

c)

a == b

b == c

c == 1

d)

abc = 1

67.

Order the below into the correct order for an assignment statement in Python. Not all options are used.

​ (a)   ​ (b)   ​ (c)  

Choose from the below words
x
=
7.3
/
@
68.

How do you declare and initialize a variable with the integer data type in Python?

​ (a)  

Choose from the below words
number = int(input("Enter a number: "))
3etNum = 5
number = input("Enter a number: "))
number = 5.0
69.

Which of the following data types can consist of numbers, alphabets and symbols?

a)

String

b)

Integer

c)

Float

d)

Boolean

70.

What will be the output from the following Python code?

print("3+4")

a)

7

b)

3+4

c)

34

d)

SyntaxError

71.

What data value would store the value: -9?

a)

Float

b)

Integer

c)

String

d)

Boolean

72.

What is programming, and why is it important for students to learn about it in today's world?

a)

a) Programming is a type of video game.

b)

b) Programming is the process of instructing a computer to perform tasks, and it's important for students to learn because it empowers them to solve problems and automate tasks.

c)

c) Programming is a form of storytelling.

d)

d) Programming is only relevant to professional software developers.


73.

How would you explain the basic syntax of Python to a beginner, and why is Python often recommended as a first programming language for students?

a)

a) Python is recommended for students because it has a complex syntax.

b)

b) Python's syntax is difficult for beginners to grasp.

c)

c) Python is recommended for its simple and readable syntax, making it accessible for beginners.

d)

d) Python is recommended because it's the only language available for students.


74.

What are some common use cases for input/output functions in Python, and how can students effectively use these functions to interact with their programs?

a)

a) Input/output functions are only used by professional programmers.

b)

b) Input/output functions in Python are used for making coffee.

c)

c) Input/output functions are used to read and write data to/from files, and to interact with users through the command line or graphical user interfaces.

d)

d) Input/output functions in Python are used for gaming purposes only.


75.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
76.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
77.
What symbol is used in python to assign values to a variable?
a)

=

b)

+

c)

*

d)

%

78.

What is a input?

a)

A function that allows us to ask the user to enter some data.

b)

To plug in something.

c)

Data displayed on a screen.

d)

A function

79.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
80.

What is the proper syntax for Python comments?

a)

<!-- Python comment -->

b)

<comment> Python comment <comment>

c)

# Python Comment

d)

/* Python Comment */

81.
What is the name of the programming language we are learning?
a)
Scratch
b)
Python
c)
Pie thin
d)
Scribble