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

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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
Quiz Jaringan Komputer
Quiz
•
11th Grade
25 questions
Java Review
Quiz
•
9th Grade - University
23 questions
Introduction to Multimedia and Photography
Quiz
•
12th Grade
24 questions
CS-9 Chapter-4 Computer Hardware Part 1: Rabin Ghimire
Quiz
•
8th - 9th Grade
30 questions
TIK
Quiz
•
9th Grade
25 questions
Informatika 1
Quiz
•
10th Grade
23 questions
Computer Science IT quiz WIP - IT Level 3 by MZH
Quiz
•
9th - 12th Grade
23 questions
ÔN TẬP CUỐI HKII
Quiz
•
4th Grade - University
Popular Resources on Wayground
5 questions
This is not a...winter edition (Drawing game)
Quiz
•
1st - 5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
10 questions
Identify Iconic Christmas Movie Scenes
Interactive video
•
6th - 10th Grade
20 questions
Christmas Trivia
Quiz
•
6th - 8th Grade
18 questions
Kids Christmas Trivia
Quiz
•
KG - 5th Grade
11 questions
How well do you know your Christmas Characters?
Lesson
•
3rd Grade
14 questions
Christmas Trivia
Quiz
•
5th Grade
20 questions
How the Grinch Stole Christmas
Quiz
•
5th Grade