
Python comprehensions, generators, and exceptions
Authored by Erik Nielsen
Computers
9th - 12th Grade
Used 6+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
28 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
The code to the left can be written more compactly as
a = 'hi' if x = 3 else 'there'
a = if x == 3: 'hi' else: 'there'
a = 'hi' if x == 3 else 'there'
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
The code to the left can be written more compactly as
b = line if ('H' in line) else ''
b = line if 'H' in line
b = if 'H' in line: line else: ''
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the result of the following statement?
print([i.upper() for i in "hello"])
[‘H’, ‘E’, ‘L’, ‘L’, ‘O’]
‘HELLO’
[‘HELLO’]
HELLO
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What datatype is x after the following statements?
a = [1, 2, 3]
x = [2*i for i in a]
list
tuple
dictionary
generator
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What datatype is x after the following statements?
a = ['hello', 3.14, 7]
x = {i: 10 for i in a}
list
tuple
dictionary
generator
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the result of the following statement?
print([i if i%2==0 else i+1 for i in range(4)])
[0, 2, 2, 4]
[1, 1, 3, 3]
error
none of the mentioned
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which list comprehension will pick out only negative integers from a given list ‘a’?
[x<0 in a]
[x for x<0 in a]
[x in a for x<0]
[x for x in a if x<0]
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
25 questions
Latihan Soal SBDPTema 4 Kelas VI
Quiz
•
9th Grade - University
25 questions
8-2 PTS INFORMATIKA
Quiz
•
8th Grade - University
27 questions
Adobe Illustrator Quiz Review
Quiz
•
9th - 12th Grade
23 questions
DDD2 Y10 19th July Networks
Quiz
•
10th Grade
25 questions
Sumatif Tengah Semester
Quiz
•
10th Grade
25 questions
CS-9 Chapter-5 Computer Software Part3: Rabin Ghimire
Quiz
•
10th Grade
24 questions
Asesment formatif : Informatika Masa Kini dan Masa Depan
Quiz
•
12th Grade
24 questions
Quiz Θεωρίας Βασικών Εννοιών Αλγορίθμων
Quiz
•
12th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade