Quiz 2 Python - Minggu Cabaran Digital

Quiz 2 Python - Minggu Cabaran Digital

10 Qs

quiz-placeholder

Similar activities

CSE 102 Exam 2 Practice

CSE 102 Exam 2 Practice

University

15 Qs

Python Pre-defined Functions

Python Pre-defined Functions

9th Grade

10 Qs

Python quiz

Python quiz

University - Professional Development

10 Qs

Loops Python

Loops Python

9th Grade

13 Qs

Python Quiz - 4

Python Quiz - 4

4th - 11th Grade

10 Qs

Code Chef Python

Code Chef Python

University

15 Qs

Python Lists

Python Lists

10th Grade

14 Qs

Python Basics

Python Basics

University

10 Qs

Quiz 2 Python - Minggu Cabaran Digital

Quiz 2 Python - Minggu Cabaran Digital

Assessment

Quiz

Computers

Medium

Created by

Ammar Yasir

Used 4+ times

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code?

x = 10

y = 2

print(x ** y)

20

5

100

12

Answer explanation

The ** operator in Python is used to calculate the power of a number. in this code, ' 10 ' raised to the power of ' 2 ' is ' 10 * 10 ', which equals 100. Therefore, the output of the print() function will be ' 100 '.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What function is used to convert a data type from string to integer?

int()

str()

float()

bool()

Answer explanation

The int() function converts a string or another number type to an integer.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. How do you get the last element in a list my_list?

my_list[0]

my_list[-1]

my_list[len(my_list)]

my_list[last]

Answer explanation

In Python, you can access elements in a list using index numbers. The first element in a list has an index of 0, the second element has an index of 1, and so on. To access the last element in a list, you can use the index -1. This is because the index -1 refers to the last element in the list, -2 refers to the second-to-last element, and so on.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What is the correct way to import the ' math ' module in Python?

import math

import Math

include math

using math

Answer explanation

The ' import ' statement is used to import the math module. Also, In Python, module names are typically written in lowercase letters, with words separated by underscores if necessary.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What does the ' // ' operator mean in Python?

Regular division

Division with remainder

Integer (floor) division

Modulus division

Answer explanation

The // operator performs integer division and returns the largest integer less than or equal to the division result.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What is the output of the following code?

a = [1, 2, 3]

b = a

b.append(4)

print(a)

[1, 2, 3]

[1, 2, 3, 4]

Error

[1, 2]

Answer explanation

In Python, assigning b = a means that b refers to the same list object as a. Thus, any modification to b also affects a.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code?

x = [1, 2, 3]

x.append([4, 5])

print(len(x))

3

4

5

6

Answer explanation

Here's an explanation of what the code does:

  1. 1. The variable x is assigned a list with three elements: [1, 2, 3].

  2. 2. The append() method is called on the list referenced by x, adding a new list [4, 5] to the end of the list.

  3. 3. The len() function is called on the list referenced by x, which returns the number of elements in the list.

Since the list [4, 5] is a single element in the list x, the length of the list x is 4. Therefore, the output of the code is 4.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?