Python comprehensions, generators, and exceptions

Python comprehensions, generators, and exceptions

9th - 12th Grade

28 Qs

quiz-placeholder

Similar activities

Computer Pretest1(Arduino Grade8_t1)

Computer Pretest1(Arduino Grade8_t1)

3rd Grade - University

25 Qs

TIK-SMT21

TIK-SMT21

9th Grade

25 Qs

9 - Word, Excel

9 - Word, Excel

9th Grade

24 Qs

Spreadsheet(Advanced Mixed Quiz)

Spreadsheet(Advanced Mixed Quiz)

10th Grade

24 Qs

FUENTE DE PODER

FUENTE DE PODER

12th Grade

24 Qs

C++ Conditionals

C++ Conditionals

10th Grade

24 Qs

IGCSE Computer Science 0478 Syllabus Quiz

IGCSE Computer Science 0478 Syllabus Quiz

9th - 12th Grade

24 Qs

Computer Pretest(Arduino)

Computer Pretest(Arduino)

12th Grade

33 Qs

Python comprehensions, generators, and exceptions

Python comprehensions, generators, and exceptions

Assessment

Quiz

Computers

9th - 12th Grade

Practice Problem

Hard

Created by

Erik Nielsen

Used 6+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

28 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

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

Media Image

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]

Create a free account and access millions of resources

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?