wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

2F-3 | Python Quiz | 14/11/2024

Total questions: 20

Worksheet time: 30mins

Name
Class
Date
1.

What will the following code output? print("Python", "Quiz", sep="*", end="123")

a)

Python*Quiz123

b)

Python*Quiz*123

c)

Python * Quiz123

d)

Python-Quiz-123

2.

How can you get integer input from the user and add 10 to it in one line of code?

a)

input() + 10

b)

str(input()) + 10

c)

int(input()) + 10

d)

float(input()) + 10

3.

What is the result of the expression 9 // 4.0 in Python?

a)

2.0

b)

2

c)

3.0

d)

3

4.

What does the sep parameter in the print() function do when used with multiple string arguments?

a)

Changes the end character

b)

Joins the strings with the given separator

c)

Adds a space between strings

d)

Causes an error

5.

Which operator can be used to perform floor division in Python?

a)

/

b)

//

c)

%

d)

**

6.

What is the output of print(int("3.5") + 1)?

a)

4.5

b)

4

c)

Error

d)

5

7.

What does print("A" * 3 + "B" * 2) produce as output?

a)

ABBB

b)

AABBB

c)

AAABB

d)

AAABBB

8.

Evaluate this expression: 10 % 4.5

a)

1.0

b)

0.5

c)

1.5

d)

0

9.

What is the output of the following code? print("Python", end="*"); print("is great!")

a)

Python is great!

b)

Python* is great!

c)

Python*is great!

d)

Python-is great!

10.

What is the output of print("Hello" + " " + str(5 * 3))?

a)

Hello15

b)

Hello 15

c)

Hello 153

d)

Error

11.

What happens if you use float(input("Enter a number: ")) and the user inputs a non-numeric string?

a)

0 is returned

b)

The string is converted to 0

c)

An error occurs

d)

The input is ignored

12.

How can you check if a variable num is an integer type in Python?

a)

type(num) == float

b)

num.is_integer()

c)

type(num) == int

d)

num.isdigit()

13.

What does the expression 10 ** (1/2) evaluate to in Python?

a)

2

b)

5

c)

3.16

d)

3.1622776601683795

14.

What will happen if you try to execute int("seven")?

a)

Converts to 7

b)

Error

c)

Converts to 0

d)

Converts to 1

15.

How can you make the following code print "Hello!World!" without changing the text inside the print() function? print("Hello", end="") followed by print("World!")

a)

Add end="!" to the first print() statement

b)

Change end="" to end=" "

c)

Add a semicolon ;

d)

Change the second print() to print(" World")

16.

Which of these will convert a float num to a string representation while limiting the number of decimal places shown to two?

a)

str(num, ".2f")

b)

f"{num:.2}"

c)

f"{num:.2f}"

d)

str.format(num, ".2f")

17.

What will be the output of print("Data" * 2 + "Science")?

a)

DataData Science

b)

DataDataScience

c)

Data*2Science

d)

Data ScienceData

18.

Which of these statements will correctly check if x is even?

a)

if x % 2 == 1:

b)

if x // 2 == 0:

c)

if x % 2 == 0:

d)

if x / 2 == 0:

19.

What is the output of print(2 + 3 * 4)?

a)

20

b)

14

c)

24

d)

18

20.

Which of the following statements correctly creates a comment in Python?

a)

// This is a comment

b)

/* This is a comment */

c)

# This is a comment

d)

<-- This is a comment -->