wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Coding Assignment

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the purpose of the "elif" statement in Python?

ment.

a)

It is used to handle exceptions.

b)

It is used to define a block of code that executes if the condition in the "if" statement is true.

c)

It is used to define a block of code that executes if the condition in the preceding "if" statement is false.

d)

It is used to define additional conditions to be checked after the initial "if" state

2.

What is the output of the following

code snippet in Python?

my_list = [1, 2, 3, 4, 5]

my_list[2] = 6

print(my_list)

a)

 [1, 2, 6, 4, 5]

b)

[1, 2, 6, 4]

c)

[1, 2, 3, 6, 5]

d)

[1, 2, 3, 4, 5, 6]

3.

Which of the following is an example

of a relational operator in Python?

a)

  +

b)

   /

c)

   ==

d)

  &&

4.

What is the output of the following

code snippet in Python?

print("Hello" + "World")

a)

Hello World

b)

HelloWorld

c)

Hello + World

d)

  Error

5.

What does the following code snippet

do?

x = 5 y = 2 result = x // y

a)

Performs integer division and stores

the quotient in the variable 'result'

b)

Calculates the remainder of x divided

by y and stores it in the variable 'result'

c)

Raises x to the power of y and stores

the result in the variable 'result'

d)

Multiplies x and y and stores the

product in the variable 'result'

6.

Which of the following is an example

of a loop that executes a fixed number of times?

a)

while loop

b)

for loop

c)

 do-while loop

d)

switch statement

7.

Which of the following is not a valid

programming language?

a)

Python

b)

Java

c)

HTML

d)

 MongoDB

8.

What will be the output of the

following code snippet?

x = [1, 2, 3, 4, 5] print(x[2:4])

a)

[2, 3]

b)

[3, 4]

c)

[2, 3, 4]

d)

[3]

9.

Which data structure follows the

"last-in, first-out" (LIFO) principle?

a)

Queue

b)

Stack

c)

Linked List

d)

Tree

10.

What is the output of the following

code snippet in Python?

def outer_function(x):

def inner_function(y):

return x + y

return inner_function

closure = outer_function(10)

result = closure(5)

print(result)

a)

10

b)

5

c)

15

d)

50

11.

Which of the following is a valid way

to comment a single-line code in Python?

a)

/* comment */

b)

<!-- comment -->

c)

# comment

d)

/* comment */

12.

What is the correct way to open a

file named "data.txt" in Python for reading?

a)

file = open("data.txt",

"r")

b)

file = open("data.txt",

"w")

c)

file = open("data.txt",

"a")

d)

file = open("data.txt",

"x")

13.

What is the correct way to check if a

key exists in a dictionary?

a)

if key in dict:

b)

if dict.contains(key):

c)

if key.exists(dict):

d)

if dict.has_key(key):

14.

What does the range() function

return?

a)

A list of integers

b)

A tuple of integers

c)

A generator object

d)

A dictionary

15.

How can you check the length of a

string in Python?

a)

length(string)

c)

len(string)

16.

What is the correct HTML tag for

inserting a line break?

a)

<br>

b)

<break>

c)

<lb>

d)

<line-break>

17.

What is the correct HTML syntax to

include an external JavaScript file?

a)

<script>src="script.js"></script>

b)

<javascript>src="script.js"</javascript>

c)

<link>src="script.js"</link>

 

d)

<js>src="script.js"</js>

18.

What will be the output of the

following code snippet?

console.log(typeof null);

a)

"null"

b)

"undefined"

c)

"object"

d)

"boolean"

19.

How to create a hyperlink in HTML?

20.

How to add a background color in

HTML?

a)

<marquee bg color:

"red">

b)

<marquee bg-color =

"red">

c)

<marquee bgcolor =

"red">

d)

<marquee color =

"red">

21.

What will be the output of the

following code snippet?

var x = 10;

function foo() {

console.log(x);

var x = 20;

}

foo();

a)

10

b)

20

c)

undefined

d)

ReferenceError

22.

What is the value of result after

executing the following JavaScript code?

let result = [1, 2, 3] + [4, 5, 6];

a)

[1, 2, 3, 4, 5, 6]

b)

"123456"

c)

NaN

d)

SyntaxError

23.

Which of the following is true about

functions in JavaScript?

a)

A function must always return a value

b)

A function can only accept a fixed number

of arguments

c)

A function can be assigned to a

variable

d)

A function can only be called once

per program execution

24.

What is the correct way to declare a

JavaScript variable?

a)

var myVariable;

b)

variable myVariable;

c)

let myVariable;

d)

const myVariable;

25.

What is the output of the following

JavaScript code snippet?

console.log(2 + "2");

a)

4

b)

22

c)

"22"

d)

NaN

26.

Which of the following CSS framework is used

to create a responsive design?

a)

django

b)

rails

c)

larawell

d)

bootstrap

27.

Which CSS selector targets an element

with a specific ID?

a)

.

b)

#

c)

d)

*

28.

.

What does CSS stand for?

a)

Cascading Style Sheets

b)

Creative Style Sheets

c)

Computer Style Sheets

d)

Colorful Style Sheets

29.

What is the correct CSS syntax to

apply a red background color to all paragraphs with the class

"highlight"?

a)

.highlight { background-color: red; }

b)

#highlight { background-color: red; }

c)

p.highlight { background-color: red;}

d)

highlight.p { background-color: red;}

30.

What is the correct way to set the font size of an element to 16 pixels in CSS?

a)

font-size: 16px;

b)

font-size: 16;

c)

size: 16px;

d)

text-size: 16px;