Python: Built-In Functions and Upto Tuple

Quiz
•
Computers
•
University
•
Hard
Mayank Saxena
Used 9+ times
FREE Resource
50 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What will print([1, 2, 3] + [4, 5]) output?
[1, 2, 3, 4, 5]
[5, 4, 3, 2, 1]
Error
[1, 2, 3, [4, 5]]
Answer explanation
The + operator concatenates two lists.
2.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
Which of the following will create a shallow copy of a list a?
b = a[:]
b = a.copy()
b = a[:]
and
b = a.copy()
both options correct
None of the above
Answer explanation
Both slicing and copy() create a shallow copy of the list.
3.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What will print(len([[1, 2], [3, 4]])) return?
2
4
8
Error
Answer explanation
The len() function returns the number of top-level elements, which is 2.
4.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
Which of the following will raise an error for tuple a?
a = (1, 2)
a[0] = 3
len((1, 2, 3))
(1, 2) + (3,)
Answer explanation
Tuples are immutable; modifying an element is not allowed.
5.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What is the output of print((1, 2) * 2)?
(1, 2, 1, 2)
(1, 2, 2)
Error
[1, 2, 1, 2]
Answer explanation
The * operator repeats the tuple.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will the following code output?
for i in range(3):
↳ for j in range(2):
↳ print(i * j, end=" ")
Note: ↳ indicating that the statement is the part of its above block
0 0 0 1 0 2
0 0 0 0 0 1
0 0 0 1
0 0 0 0 1 2
Answer explanation
The nested loops compute i * j for all combinations of i and j.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Error Correction: Fix the code to break the loop:
i = 0
while True:
↳print(i)
↳if i == 5:
↳break
Note: ↳ indicating that the statement is the part of its above block
Add i += 1 before break
Use for instead of while
Add i += 1 after print(i)
Replace break with continue
Answer explanation
Increment i after print(i) to avoid an infinite loop.
Create a free account and access millions of resources
Similar Resources on Wayground
50 questions
Sistem Komputer gerbang aritmatika Kelas 10

Quiz
•
12th Grade - University
50 questions
Java Array Questions

Quiz
•
University
50 questions
Latihan Soal Berpikir Komputasional

Quiz
•
2nd Grade - University
45 questions
software engineering

Quiz
•
University
49 questions
MATLAB Quiz

Quiz
•
University
45 questions
Networking and Wireless Communication Quiz

Quiz
•
University
50 questions
IP Address

Quiz
•
University
50 questions
FINAL TEST FOR JAVA PROGRAMMING 2

Quiz
•
University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

Quiz
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
15 questions
Properties of Equality

Quiz
•
8th Grade - University
38 questions
WH - Unit 3 Exam Review*

Quiz
•
10th Grade - University
21 questions
Advise vs. Advice

Quiz
•
6th Grade - University
12 questions
Reading a ruler!

Quiz
•
9th Grade - University