What is the output of the following code?
x = 10
y = 2
print(x ** y)
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.
15 questions
SCRIPTING PROGRAMMING WITH PYTHON
Quiz
•
University
15 questions
Python Basics
Quiz
•
6th - 8th Grade
10 questions
نشاط الدوال المضمنة الخاصة بالأرقام
Quiz
•
10th Grade
15 questions
HCI 584 Python quiz
Quiz
•
University
7 questions
Python Data Types and Arithmetic Quiz
Quiz
•
8th Grade
14 questions
Python Basics
Quiz
•
7th Grade
10 questions
Homework 3- Python
Quiz
•
8th Grade
14 questions
Basic Python Quiz 3
Quiz
•
5th Grade
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade