Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Sandbox 2

Total questions: 40

Worksheet time: 21mins

Name
Class
Date
1.

Which of the following is a valid variable name in Python?

a)

2number

b)

number_2

c)

number-2

d)

number 2

2.

What is the output of the following code?

print(5 + 3)

a)

53

b)

8

c)

5+3

d)

15

3.

Which operator is used for multiplication in Python?

a)

+

b)

*

c)

/

d)

%

4.

Which of the following is a comparison operator in Python?

a)

=

b)

==

c)

:=

d)

++

5.

What is the result of the following expression: 7−47 - 4 ?

a)

3

b)

11

c)

4

d)

7

6.

Which function is used to display output in Python?

a)

output()

b)

print()

c)

show()

d)

display()

7.

Which of the following is a logical operator in Python?

a)

and

b)

plus

c)

not_equal

d)

add

8.

What is the data type of the value 3.14 in Python?

a)

int

b)

float

c)

str

d)

bool

9.

Which statement will assign the value 10 to the variable x?

a)

x == 10

b)

x := 10

c)

x = 10

d)

10 = x

10.

What does the following code print? print("Hello, World!")

a)

Hello World

b)

Hello, World!

c)

"Hello, World!"

d)

HelloWorld

11.

Which of the following expressions evaluates to True?

a)

5 > 10

b)

7 == 7

c)

3 < 2

d)

8 != 8

12.

What is the output of the following code? x = 4 y = 2 print(x / y)

a)

2

b)

2.0

c)

4

d)

0.5

13.

Which of the following statements will print "Yes" if the variable score is greater than 50?

a)

if score > 50: print("Yes")

b)

if score = 50: print("Yes")

c)

if score < 50: print("Yes")

d)

if score == 50: print("Yes")

14.

What will be the value of z after executing the following code? x = 5 y = 3 z = x * y

a)

8

b)

15

c)

2

d)

53

15.

Which of the following will evaluate to False?

a)

10 < 20 and 5 > 2

b)

7 == 7 or 3 > 5

c)

not (4 == 4)

d)

6 != 6

16.

What is the output of the following code? a = 8 b = 2 print(a // b)

a)

4

b)

4.0

c)

8

d)

0.25

17.

Which of the following is the correct way to check if a variable x is not equal to 10?

a)

if x =! 10:

b)

if x != 10:

c)

if x <> 10:

d)

if x not 10:

18.

What is the output of the following code? x = 7 if x > 5: print("Big") else: print("Small")

a)

Big

b)

Small

c)

7

d)

Error

19.

Which of the following will print "True"? a = 3 b = 5 print(a < b and b > 2)

a)

True

b)

False

c)

3

d)

5

20.

What is the output of the following code? ```python x = 10 y = 5 if x == y: print("Equal") else: print("Not Equal") ```

a)

Equal

b)

Not Equal

c)

10

d)

5

21.

Given the following code, what will be printed? x = 4 y = 6 if x + y > 10: print("High") else: print("Low")

a)

High

b)

Low

c)

10

d)

4

22.

Which of the following code snippets will print "Pass" only if both math and science scores are above 60?

a)

if math > 60 or science > 60: print("Pass")

b)

if math > 60 and science > 60: print("Pass")

c)

if math >= 60 and science >= 60: print("Pass")

d)

if math > 60: print("Pass")

23.

What will be the output of the following code? x = 3 y = 7 if x * y > 20: print("Large") else: print("Small")

a)

Large

b)

Small

c)

21

d)

Error

24.

Which of the following expressions will result in True?

a)

(5 > 3) and (2 < 1)

b)

(4 == 4) or (6 < 2)

c)

not (7 > 8)

d)

(3 != 3) and (1 == 1)

25.

Given the code below, what will be printed? x = 12 if x % 2 == 0: print("Even") else: print("Odd")

a)

Even

b)

Odd

c)

12

d)

Error

26.

Which of the following code snippets will print "Yes" if either a is greater than 10 or b is less than 5?

a)

if a > 10 and b < 5: print("Yes")

b)

if a > 10 or b < 5: print("Yes")

c)

if a >= 10 and b <= 5: print("Yes")

d)

if a == 10 or b == 5: print("Yes")

27.

What will be the output of the following code? ```python x = 5 y = 10 if x > y: print("x is bigger") else: print("y is bigger") ```

a)

x is bigger

b)

y is bigger

c)

5

d)

10

28.

Which of the following will print "True" if x is between 1 and 10 (inclusive)?

a)

if x > 1 and x < 10: print("True")

b)

if x >= 1 and x <= 10: print("True")

c)

if x == 1 or x == 10: print("True")

d)

if x > 0 and x < 11: print("True")

29.

Given the following code, what will be printed? x = 9 y = 3 if x / y == 3: print("Yes") else: print("No")

a)

Yes

b)

No

c)

3

d)

9

30.

Which of the following code snippets will print "Equal" if a and b are the same, and "Not Equal" otherwise?

a)

if a = b: print("Equal") else: print("Not Equal")

b)

if a == b: print("Equal") else: print("Not Equal")

c)

if a != b: print("Equal") else: print("Not Equal")

d)

if a == b: print("Not Equal") else: print("Equal")

31.

In the following code, n is a/an _______?


n = '5'

a)

integer

b)

string

c)

tuple

d)

operator

32.

What is a string in programming?

a)

A type of function

b)

A collection of integers

c)

An ordered sequence of characters

d)

A type of boolean value

33.

Which of the following is a characteristic of a string?

a)

It can execute functions

b)

It is a primary data type for storing numerical values

c)

It represents text as a sequence of characters

d)

It can only contain spaces and letters

34.

a="True"

print(a)

What is the output?

a)

True

b)

bool

c)

str

d)

Syntax Error

35.

What data type is used to store whole numbers without decimals in programming?

a)

float

b)

double

c)

Int

d)

user Input

36.

Which data type show true or false value?

a)

int

b)

boolean

c)

string

37.

Which data type stores values as True or False?

a)

Boolean (bool)

b)

String (str)

c)

Python If ... Else

d)

while x < 10:

38.

Which one is the example of the data types int?

a)

A

b)

28.02

c)

19

d)

aliya@yahoo.com

39.
A(n) float is:
a)
A precise number by including values after the decimal place
b)
A programming statement that directs control flow - it uses BOOLEAN expressions to make a choice between different paths (IF (condition) THEN (path1) ELSE (path2)
c)
A data type that can have only 2 values - TRUE or FALSE
d)
A whole number, it does not have any digits after a decimal.
40.

What does the term 'Data Type' refer to in programming?

a)

String, integer, or Boolean

b)

Domain

c)

Equals

d)

Logical Operators