Search Header Logo

Python 3

Computers

9th - 12th Grade

Used 6+ times

Python 3
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

30 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You have the following code:


y=2

x=0

while x*Y < 8:

if x == 3:

pass

while x < 2:

x = x+1

x +=1

What will be the value of x?

6

5

7

4

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You have the following code:

n= 4

x = 1

You need to print out a multiplication table for 4 X 1 through 4 X 10, with each output on a separate line.

The first output should be : 4 X 1 = 4

The last output should be : 4 X 10 = 40

Which code segment should you use?

while x < 11:

print(str(n) + 'x' + str(x) + ' = ' + str(n*x))

x +=1

while x <= 11:

print(str(n) + 'x' + str(x) + ' = ' + str(n*x))

x +=1

while x <11:

print(str(n) + 'x' + str(x) + ' = ' + (n*x))

x += 1

while x < 11:

print(str(n) + 'x' + str(x) + ' = ' + str(n*x))

x += 1

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You have the following code:

n = 2

x = 7

for i in range (5,x):

while i < 6:

n = n +1

if n == 2:

pass

else:

n += 1

i += 1

What will be the value of n?

5

6

7

4

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You need to write the following list to a CSV file:

students = [["Mark", "A"], ["Bryan", "B"], ["Lisa", "B"], ["Jessica", "C"],["Tim", "A"]]


Which code segment should you use?

import csv

with open("students.csv", "w", newline="") as f:

f.writerows(students)

import csv

with open("students.csv", "w", newline="") as f:

writer = csv.writer(f)

writer.writerows(students)

import csv

with open("students.csv", "w", newline="") as f:

writer = csv.writer(f)

writer.write(students)

import csv

with open("students.csv", "wb", newline="") as f:

writer = csv.writer(f)

writer.writerows(students)

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You have the following snippet:

import pickle

course_count = [["C++", "24"], ["Java", "32"], ["Python", "38"], ["JavaScript", "29"], ["C#", "40"]]

# add missing code here

with open("languages.bin", "rb") as f:

course_count2 = pickle.load(f)

print(course_count2)

You need to add the missing code to write the list to a binary file.

Which code fragment should you use?

with open("languages.bin", "wb") as f:

pickle.write(course_count, f)

with open("languages.bin", "wb" as f:

writer = pickle.writer(f)

writer.dump(course_count)

with open("languages.bin", "wb") as f:

pickle.dump(course_count, f)

with open("languages.bin", "b") as f:

pickle.dump(course_count, f)

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You need to write some contents to a file named file_name that will be in the following format:


Hello World!


Which code segment should you use?

f = open('file_name')

f.write('Hello World!')

f.close()

f = open('file_name', 'w')

f.write('Hello World!')

f.close()

f = open('file_name', 'r')

f.write('Hello World!')

f.close()

f = open('file_name', 'b')

f.write('Hello World!')

f.close()

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

You have a file named studentfile with the following content:


Dave, 100, 90, 77

Sam, 55, 90, 80


You need to write code to read all of the contents of the file.


Which code segment should you use?

with open('studentfile') as f:

file_data = f.read()

with open('studentfile', 'r') f:

file_data = f.read()

with open('studentfile', 'w') as f:

file_data = f.read()

with open('studentfile') as f:

file_data = f.readline()

Access all questions and much more by creating a free account

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?