Quiz 2 Python - Minggu Cabaran Digital

Quiz
•
Computers
•
•
Medium
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
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
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
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
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
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. The variable x is assigned a list with three elements: [1, 2, 3].
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. 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
Similar Resources on Wayground
10 questions
Python Basics

Quiz
•
University
15 questions
CSE 102 Exam 2 Practice

Quiz
•
University
10 questions
Python Pre-defined Functions

Quiz
•
9th Grade
13 questions
Loops Python

Quiz
•
9th Grade
14 questions
Python Syntax

Quiz
•
6th - 12th Grade
11 questions
Conditional statements

Quiz
•
7th Grade
15 questions
Python Programming Random Quiz

Quiz
•
11th Grade
15 questions
list in python

Quiz
•
10th - 12th Grade
Popular Resources on Wayground
55 questions
CHS Student Handbook 25-26

Quiz
•
9th Grade
18 questions
Writing Launch Day 1

Lesson
•
3rd Grade
10 questions
Chaffey

Quiz
•
9th - 12th Grade
15 questions
PRIDE

Quiz
•
6th - 8th Grade
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
22 questions
6-8 Digital Citizenship Review

Quiz
•
6th - 8th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade