Python 3

Python 3

9th - 12th Grade

30 Qs

quiz-placeholder

Similar activities

Python for Absolute Beginners

Python for Absolute Beginners

8th - 12th Grade

25 Qs

Data Types- Python

Data Types- Python

7th - 11th Grade

25 Qs

Python Lessons 1 & 2 Review

Python Lessons 1 & 2 Review

9th - 12th Grade

26 Qs

Python GCSE

Python GCSE

10th Grade

27 Qs

C Programming Quiz

C Programming Quiz

12th Grade

25 Qs

Python set 1

Python set 1

9th - 12th Grade

26 Qs

[AP CSP] Programming Lesson 1 - Input/Output, Data Types

[AP CSP] Programming Lesson 1 - Input/Output, Data Types

9th - 12th Grade

25 Qs

R081 LO3 - Be able to produce pre-production documents

R081 LO3 - Be able to produce pre-production documents

10th - 11th Grade

27 Qs

Python 3

Python 3

Assessment

Quiz

Computers

9th - 12th Grade

Hard

Used 6+ times

FREE Resource

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()

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?