wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Assignment 2(CIVIL)

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

1. What is the output of the following for loop and  range() function

for num in range(-2,-5,-1):

print(num, end=", ")

a)
  • -2, -1, -3, -4

b)
  • -2, -1, 0, 1, 2, 3,

c)
  • -2, -1, 0

d)
  • -2, -3, -4,

2.

Given the nested if-else structure below, what will be the value of x after code execution completes

x = 0

a = 0

b = -5

if a > 0:

if b < 0:

x = x + 5

elif a > 5:

x = x + 4

else:

x = x + 3

else:

x = x + 2

print(x)

a)

2

b)

0

c)

3

d)

4

3.

What is the output of the following range() function

for num in range(2,-5,-1):

print(num, end=", ")

a)
  • 2, 1, 0

b)
  • 2, 1, 0, -1, -2, -3, -4, -5

c)
  • 2, 1, 0, -1, -2, -3, -4

d)
  • 2, 1, 0, -1, -2

4.

What is the output of the following if statement

a, b = 12, 5

if a + b:

print('True')

else:

print('False')

a)
  • False

b)
  • True

5.

Which of the following is a valid conditional statement in Python?

a)

if a = 5:

b)

if a == 5:

c)

if a <> 5:

d)

if (a = 5):

6.

What is the outcome if the elif and else blocks are missing in an if statement?

a)

Syntax error

b)

he program will stop

c)

Nothing, it's optional

d)

Runtime error

7.

What is the output of the following code?

x = 10;
if x > 5:
print("Greater")

a)

Error

b)

Greater

c)

Nothing

d)

Less

8.

What will the following code print?
x = 10;
if x < 10:
print("Less");

else:
print("Not Less")

a)

Less

b)

Not Less

c)

Error

d)

Nothing

9.

What is printed when the temperature is 25 degrees?

If temperature > 30,
print "Hot",
elif temperature > 20,
print "Warm",

else
"Cold"

a)

Prints "Hot"

b)

Prints "Warm"

c)

Prints "Cold"

d)

No output

10.

Identify the error:

if x > 10
print("Greater")

a)

Missing parentheses around condition

b)

No error

c)

Missing colon after condition

d)

Incorrect comparison operator

11.

What is the use of a for loop in Python?

a)

To repeat a block a fixed number of times

b)

To check a condition

c)

To declare variables

d)

To handle exceptions

12.

Which statement immediately terminates a loop in Python?

a)

break

b)

continue

c)

exit

d)

stop

13.

What does the continue statement do inside a loop?

a)

Pauses the loop

b)

Stops the loop

c)

Skips the current iteration

d)

Exits the program

14.


In a while loop, what happens if the condition never becomes False?

a)

The loop runs forever

b)

The loop stops after 10 iterations

c)

Syntax error

d)

The loop doesn't start

15.

What is the output of the following code?

for i in range(3):
print(i)

a)

"0 1 2"

b)

"1 2 3"

c)

"0 1 2 3"

d)

"Error"

16.


What will the following code print?

i = 5;
while i > 0:
print(i);
i -= 1

a)

5 4 3 2 1

b)

5 4 3 2

c)

1 2 3 4 5

d)

Infinite loop

17.


How do you access the last element of a list named myList?

a)

myList[0]

b)

myList[-1]

c)

myList[len(myList)]

d)

myList[-2]

18.

What is a function in Python?

a)

A variable

b)

A module

c)

A block of code

d)

An operator

19.

What is the difference between arguments and parameters in Python functions?

a)

No difference

b)

Parameters define, arguments call

c)

Arguments define, parameters call

d)

Based on data type

20.


What will the following function return:

def example():
return 5+5

a)

5+5

b)

10

c)

0

d)

None

21.

What is the output of this code:

def add(x, y):
return x + y;
print(add(3, 4))

a)

3

b)

4

c)

7

d)

Error

22.


Identify the error:

def my_func(x, y):
return x + y;
my_func(1)

a)

Missing argument

b)

Syntax error

c)

Logic error

d)

No error

23.

Find the mistake:

import math;
print(math.sqr(4))

a)

Incorrect module

b)

Incorrect function name

c)

Wrong number of arguments


d)

No error

24.

Which of the following is the use of id() function in python?

a)

Every object in Python doesn’t have a unique id

b)

In Python Id function returns the identity of the object

c)

None of the mentioned

d)

All of the mentioned

25.

Guess the correct output of the following code?

str1 = "PYnative" print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])

a)

PYn PYnat ive PYnativ vitanYP

b)

Yna PYnat tive PYnativ vitanYP

c)

Yna PYnat tive PYnativ PYnativ