Quiz
Python 2
Dieses Quiz enthält Fragetypen, die sich im gewohnten Player öffnen.
Fragen in diesem Quiz (26)
1A company needs help updating their file system. You must create a simple
file-manipulation program that performs the following actions:
Creates a file using the specified name.
Appends the phrase "End of listing" to the file.
You need to complete the code to meet the requirements.
Complete the code by selecting the correct code segment from each drop-down list.
import os
file = [blank_start]1[blank_end]
[blank_start]2[blank_end] ("End of listing")
file.close()- Aopen("myFile.txt","a")
- Bfile.write
- Copen("myFile.txt","a")
- Dfile.write
2You are writing a program to randomly assign rooms (room_number) and team-building
groups (group) for a company retreat.
Complete the code by selecting the correct code segment from each drop-down list.
import random
roomsAssigned=[1]
room_number=1
groupList=["Ropes","Rafting","Obstacle","Wellness"]
count=0
print("Welcome to CompanyPro's Team-Building Weekend!")
name=input("Please enter your name (q to quit)? ")
while name.lower() != 'q' and count < 50:
while room_number in roomsAssigned:
[blank_start]1[blank_end]
print(f"{name}, your room number is {room_number}")
roomsAssigned.append(room_number)
[blank_start]2[blank_end]
print(f"You will meet with the {group} Group this afternoon.")
count+=1
name=input("Please enter your name (q to quit)? ")- Aroom_number=random.randint(1,50)
- Broom_number=random.randint(50)
- Croom_number=random.range(1,50)
- Droom_number=random.choice(1,50)
- Egroup = random.chioce(groupList)
- Fgroup = random.randint(groupList)
- Ggroup = random.shuffle(groupList)
- Hgroup = groupList(random.randint(0,3))
3A company needs help updating their file system.
You must create a simple file-manipulation program that performs the following actions:
- Checks to see whether a file exists.
- If the file exists, displays its contents.
Complete the code by selecting the correct code segment from each drop-down list.
import os
if [blank_start]1[blank_end]
file = open('myFile.txt')
[blank_start]2[blank_end]
file.close()- Aos.exist("myFile.txt"):
- Bos.path("myFile.txt"):
- Cos.file.exists("myFile.txt"):
- Dos.find("myFile.txt"):
- Eprint(file.read())
- Fprint(read(file))
- Gprint(file.open())
- Hfile.write()
4You need to identify the results of performing various slicing operations on the
following sequence structure:
alph = "abcdefghijklmnopqrstuvwxyz"
Move the appropriate results from the list on the left to the correct slicing operations
on the right.
You may use each result once, more than once, or not at all.
alph[3:6] [blank_start]1[blank_end]
alph[:6] [blank_start]2[blank_end]- Adef
- Bcde
- Ccdef
- Ddefg
- Eabcde
- Fabcdef
5You find errors while evaluating the following code. Line numbers are included for
reference only.
01 numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
02 index = 0
03 while(index < 0)
04 print(numbers[index])
05
06 if numbers(index) = 6
07 break
08 else:
09 index += 1
You need to correct the code at line 03 and line 06.
Evaluate the code and answer the questions by selecting the correct option from each
drop-down list.
Which code segment should use at line 03? [blank_start]1[blank_end]
Which code segment should use at line 06? [blank_start]2[blank_end]- Awhile (index < 10):
- Bwhile (index <= 10):
- Cwhile index < 10
- Duntil (index == 10):
- Eif numbers[index] == 6:
- Fif numbers[index] = 6:
- Gif numbers(index) == 6:
- Hif numbers[index] == 6
6A game development company needs a way to find the number of words in a list that
contain a specific letter.
Complete the code by selecting the correct code segment from each drop-down list.
Note: You will receive partial credit for each correct selection.
# Function accepts list of words and letter to search for.
# Returns count of the number of words that contain that letter.
def count_letter(letter, word_list):
count = 0
for [blank_start]1[blank_end]
if [blank_start]2[blank_end]
count += 1
return count
# word_list is populated by the readWords() function. Code not shown.
word_list = readWords()
letter = input("Which letter would you like to count")
etter count = count letter(letter, word_list)
print("There are: ", letter_count, " words that contain ", letter)- Aword in word_list:
- Bword_list in word:
- Cword in range(word_list):
- Dword in word_list
- Eletter in word:
- Fword in letter:
- Gletter == word:
- Hletter.find(word):
7You are creating a Python program that will let a user guess a number from 1 to 10.
The user is allowed up to three guesses. If the user guesses the correct number, the
program must stop asking for guesses. Complete the code by moving the appropriate code
segments from the list on the left to the correct locations on the right. You may use
each code segment once, more than once, or not at all.
from random import randint
target= randint(1,10)
chance = 1
print("Guess an integer from 1 to 10. You will have 3chances.")
[blank_start]1[blank_end]
guess = int(input("Guess an integer: "))
if guess > target:
print("Guess is too high")
elif guess < target:
print("Guess is too low" )
else:
print("Guess is just right!" )
[blank_start]2[blank_end]
[blank_start]3[blank_end]- Awhile chance <=3:
- Bwhile chance <3
- Cwhile chance < 3:
- Dpass
- Echance = 2
- Fbreak
- Gchance +=1
8A company asks you to debug some code that is causing problems with their payroll. They
ask you to find the source of the payroll errors.
The following variables have been declared:
employee_pay =[15000, 120000, 35000, 45000]
count = 0
sum = 0
There are two errors in the following code:
for index in range(0, len(employee_pay)-1):
count += 1
sum += employee_pay[index]
average = sum/count
print("The total payroll is:", sum)
print("The average salary is:", average)
Which code should you use to fix the errors?
To answer, select the appropriate code segments in the answer area.
for index in range [blank_start]1[blank_end]
count += 1
sum += employee_pay[index]
average = [blank_start]2[blank_end]
print("The total payroll is:", sum)
print("The average salary is:",average)- A(len(employee_pay)):
- B(0, len(employee_pay) - 1):
- C(len(employee_pay) + 1):
- D(employee_pay):
- Esum/count
- Fcount/sum
- Gsum/len(range)
- Hemployee_pay/count
9You are creating a program to calculate the rental fee for DVDs. The fee structure is as
follows:
. The default cost ('cost_per_night') is $1.59 per night
. If the customer returns the DVD after 8 PM, they are charged for an extra night.
. Sunday DVD rentals receive a 30% discount for the full length of the rental.
. Thursday DVD rentals receive a 50% discount for the full length of the rental.
Complete the code to meet the requirements by selecting the correct code segment from
each dropdown list.
#DVD Rental Calculator
ontime = input("Was the video returned before 8 PM? Y or N").lower()
days_rented = int(input("How many days was the video rented?"))
weekday = input("What day was the video rented?").capitalize()
cost_per_night = 1.59
if on time [blank_start]1[blank_end]
days_rented +=1
if weekday [blank_start]2[blank_end]
total =(days_rented * cost_per_night) * 0.7
elif weekday [blank_start]3[blank_end]
total = (days_rented * cost_per_night) * 0.5
else:
total = days rented * cost per night
print("Cost of the DVD rental is : $", total)- A== "n":
- B= "n":
- C== "N":
- Dis "n"
- E== "Sunday":
- F== "sunday":
- Gin "Sunday":
- H= "Sunday":
- I== "Thursday"
- J== "thursday"
- K== "Thursday":
- L!= "Thursday"
10You need to write code that performs the following tasks:
. Call the process() function.
. If the process() function throws an error, call the logError() function.
. Always call the displayResult() function after calling the process() function.
Complete the code by moving the appropriate code segments from the list on the left to
the correct locations on the right.
[blank_start]1[blank_end] process()
[blank_start]2[blank_end] logError
[blank_start]3[blank_end] displayResult()- Atry:
- Bassert:
- Craise:
- Dexcept:
- Efinally:
11You are writing code to create an E shape from asterisks. You need to print five lines
of code
with four asterisks each on the first, third, and fifth lines and one asterisk each on
the second and fourth lines, as shown.
****
*
****
*
**.
Complete the code by selecting the correct numbers in the boxes. Enter each number as an
integer.
result str=""
for row in range(1, [blank_start]1[blank_end])
for column in range(1,[blank_start]5[blank_end])
if (row == 1 or row == 3 or row == 5):
result str = result str +"*"
elif column == 1:
result_str = result str+"*"
result str = result str +"in"
print(result_str)- A6
- B5
- C0
- D7
- E5
- F4
- G1
- H6
12You are writing a Python program that evaluates an arithmetic formula.
The formula is described as
"*b equals a multiplied by negative one, then raised to the second power ** ,
where a' is the value that will be input and 'b' is the result.
You create the following code segment. Line numbers are included for reference only:
01 a = int(input("Enter a number for the equation: "))
02 b= [blank_start]1[blank_end] [blank_start]2[blank_end] [blank_start]3[blank_end] [blank_start]4[blank_end] [blank_start]5[blank_end]
Complete the code on line 02 by dragging the appropriate code segments into the correct
locations.
You may use each code segment once, more than once, or not at all.- A(
- B**
- C2
- D-
- Ea
- F)
- G**2
13Answer the questions about documenting Python code by selecting the correct option from
each drop-down list.
Whitch caracter(s) signal the beginning and ending of single-line docstring? [blank_start]1[blank_end]
When documenting a function, what is the standart location for the docstring? [blank_start]2[blank_end]
Review the following function:
def cube(n):
""" Returns the cube of number n """
return n*n*n
Whitch command will print the docstring? [blank_start]1[blank_end]- A"""
- B#
- C//
- D/*
- EImmediately after the function header
- FBefore the function header
- GImmediately before the return statement
- HOutside the function body at the end of
- Iprint(cube.__doc__)
- Jprint(cube.doc)
- Kprint(cube.__doc__())
- Lprint(help(cube.__doc__))
14You are developing a Python program for an online product distribution company.
The program must iterate through a list of products ( productldList') and escape when it
finds a specific product ID.
Complete the code by selecting the correct code segment
from each drop-down list.
productldList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
index= 0
[blank_start]1[blank_end] (index < 10):
print(productldList[index])
if productldList[index] == 6:
[blank_start]2[blank_end]
else:
[blank_start]3[blank_end]- Awhile
- Bfor
- Cif
- Dloop
- Ebreak
- Fcontinue
- Gexit
- Hreturn
- Iindex += 1
- Jindex =+ 1
- Kindex++
- Lcount += 1
15You write the following code:
a ='Config1'
print(a)
b = a
a += 'Config2'
print(a)
print(b)
Evaluate the code and answer the questions by selecting the correct option from each
drop-down list.
What is displayed after the second print? [blank_start]1[blank_end]
What is displayed after the third print? [blank_start]2[blank_end]- AConfig1Config2
- BConfig2
- CTypeError
- DConfig1
- EConfig1Config2
- FConfig2
- GNameError
16You are writing code to return a letter grade based on the following criteria:
- Thevariable grade' stores the numeric grade as a whole number between 0 and 100.
- Grades from 90 to 100 = A.
- Grades from 80 to 89 = B
- Grades from 70 to 79 = C.
- All other grades are failing.
Complete the code by selecting the correct code segment from each drop-down list.
[blank_start]1[blank_end] grade <= 100:
[blank_start]2[blank_end] grade>= 90:
print("Your grade is A.")
[blank_start]3[blank_end] grade >= 80:
print("Your grade is B.")
[blank_start]4[blank_end] grade < 80 [blank_start]5[blank_end] grade> 69:
print("Your grade is C.")
[blank_start]6[blank_end]
print("Your grade is failing.")
[blank_start]7[blank_end]
print("Invalid grade entered.")- Aif
- Belse
- Celif
- Dand
- Eif
- Felse
- Gelif
- Hand
- Ielif
- Jelse
- Kand
- Lif
- Melif
- Nelse
- Oif
- Pand
- Qif
- Relse
- Sand
- Telif
- Uelse
- Velif
- Wif
- Xand
- Yelse
- Zelif
- AAand
- ABif
17You are writing a function to read a data file and print the results as a formatted table.
You write code to read a line of data into a list named fields.
The printout must be formatted to meet the following requirements:
· Fruit name (fields[0]): Left-aligned in a column 10 spaces wide.
· Weight (fields[1]): Right-aligned in a column 5 spaces wide with one digit after the decintl point.
· Price (fields[2]): Right-aligned in a column 7 spaces wide with two digits after the decimal point.
The following shows a sample output:
Oranges 5.6 1.33
Complete the code using drag-and-drop by placing the correct formatting segments:
print(" [blank_start]1[blank_end] [blank_start]2[blank_end] [blank_start]3[blank_end]".format(fields[0], eval(fields[1]), eval(fields[2])))- A{0:10}
- B{10:0)
- C{5:1f}
- D(7:2f)
- E{1:5.1f)
- F(2:7.2f)
18You are writing a program that calculates a user's approximate year of birth.
The program asks users for the user's age ('age') and the current year ( year'),
then outputs the user's approximate year of birth ('born') in a message ('message').
You write the following code:
age = input("Enter your age:")
year = 2000
born = year - int(age)
message = "You were born in " + str(born)
print(message)
Evaluate the code and answer the questions by selecting the correct option from each drop-down list.
What data type is age in line 01? [blank_start]1[blank_end]
What data type is born in line 03? [blank_start]2[blank_end]
What data type is message in line 05? [blank_start]3[blank_end]- Aint
- Bstring
- Cfloat
- Dint
- Efloat
- Fstring
- Glist
- Hstring
- Iint
- Jtext
- Kfloat
19Complete the statements about assert methods by selecting the correct option from each drop-down list.
To test that the value of variables a and b are the same, use: [blank_start]1[blank_end]
To test that objects a and b are the same, use: [blank_start]2[blank_end]
To test weather a value exists in a list, use: [blank_start]3[blank_end]- AassertEqual(a, b)
- BassertValue(a, b)
- CassertEqual(a == b)
- DassertSame(a, b)
- EassertIs(a, b)
- FassertSameObject(a, b)
- GassertIdentity(a, b)
- HassertIsInstance(a, b)
- IassertIn(a, b)
- JassertContains(a, b)
- KassertExists(a, b)
- LassertIn(b, a)
20You are writing a function to perform safe division of numbers.
You need to ensure that a denominator and numerator are passed to the function and that the denominator is not zero.
Complete the code by selecting the correct code segment from each drop-down list.
def safe_divide(numerator, denominator):
[blank_start]1[blank_end]
print("A required value is missing.")
[blank_start]2[blank_end]
print("The denominator is zero.")
else:
return numerator / denominator- Aif numerator is None ordenominatorisNone
- Belif denominator == 0:
- Celif denominator == 0:
- Dif denominator == 0:
- Eelif denominator = 0:
- Felse denominator == 0:
21You create the following program to locate a conference room and display the room name.
The program outputs "Room does not exist." even when 1 or 2 is entered.
01 rooms = {1: 'Foyer', 2: 'Conference Room'}
02 room = input('Enter the room number: ')
03 if not room in rooms:
04 print('Room does not exist.')
05 else:
06 print("The room name is " + rooms[room])
Evaluate the code and answer the questions by selecting the correct option from each drop-down list.
Which two data types are stored in the rooms dictionary at line 01? [blank_start]1[blank_end]
What is the data type of room at line 02? [blank_start]2[blank_end]
Why does line 03 fail to find the rooms? [blank_start]3[blank_end]- Aint and string
- Bstring and float
- Clist and tuple
- Dobject and array
- Eint
- Ffloat
- Gstr
- Hdict
- IInvalid synta/Data type mismatch
- JKeyError
- KDictionary is empty
22You are creating an interactive Times Table Helper program intended for elementary school children.
You need to complete a function named times_tables that computes and displays all multiplication table results from 2 to 12, as shown below:
4 6 8 10 12 14 16 18 20 22 24
6 9 12 15 18 21 24 27 30 33 36
8 12 16 20 24 28 32 36 40 44 48
10 15 20 25 30 35 40 45 50 55 60
12 18 24 30 36 42 48 54 60 66 72
14 21 28 35 42 49 56 63 70 77 84
16 24 32 40 48 56 64 72 80 88 96
18 27 36 45 54 63 72 81 90 99 108
20 30 40 50 60 70 80 90 100 110 120
22 33 44 55 66 77 88 99 110 121 132
24 36 48 60 72 84 96 108 120 132 144
Complete the missing code segments by selecting the correct options from each drop-down list.
# Display time tables 2 - 12
def times_tables():
[blank_start]1[blank_end]
[blank_start]2[blank_end]
print(row * col, end ="")
print(
# main
times_tables()- Afor col in range(2, 13):
- Bfor col in range(2, 12):
- Cfor col in range(13):
- Dfor col in range(2, 13)
- Efor row in range(2, 13):
- Ffor row in range(2, 12):
- Gwhile row < 13:
- Hfor row in col:
23You are writing a Python application that includes multiple operations on the same line
You need to determine the correct order of operations.
of code.
Move the type of operation from the list on the left to the correct locations on the
with the type of operation that will be performed first at the top and the type of
right.
operation
that will be performed last at the bottom.
Operation type performed first: [blank_start]1[blank_end]
Operation type performed second: [blank_start]2[blank_end]
Operation type performed third: [blank_start]3[blank_end]
Operation type performed fourth: [blank_start]4[blank_end]
Operation type performed fifth: [blank_start]5[blank_end]
Operation type performed last: [blank_start]6[blank_end]- AParentheses
- BExponents
- CUnary positive, negative, not
- DMultiplication and Division
- EAddition and Subtraction
- FAnd
24You need to identify the data types of various type operations.
Move the appropriate data types from the list to the correct type operations on the
right.
You may use each data type once, more than once, or not at all.
type(+1E10) [blank_start]1[blank_end]
type(5.0) [blank_start]2[blank_end]
type("True") [blank_start]3[blank_end]type(False) [blank_start]4[blank_end]- Aint
- Bfloat
- Cstr
- Dbool
2501 import datetime
02 dailySpecials=("Spaghetti","Macaroni and Cheese","Meatloaf","Fried Chicken")
03 weekendSpecials=("Lobster","Prime Rib","Parmesan-Crusted Cod")
04
05
06 print("My Healthy Eats Delivery")
07 if today == "Friday" or today == "Saturday" or today == "Sunday":
08 print("The weekend specials include:")
09 for item in weekendSpecials:
10 print(item)
11 else:
12 print("The weekday specials include: ")
13 for item in dailySpecials:
14 print(item)
15
16 print(f"Pricing specials change in {daysLeft} days")
Complete the code in lines 04, 05, and 15 by selecting the correct option from each
drop-down list.
In line 04, retrieve the current date. [blank_start]1[blank_end]
In line 05, retrieve the weekday. [blank_start]2[blank_end]
In line 15, calculate the number of days left in the week. [blank_start]3[blank_end]- Anow = datetime.datetime.now()
- Bnow = datetime.now()
- Cnow = datetime.datetime.today
- Dnow = datetime.date()
- Etoday = now.strftime("%A")
- Ftoday = now.strftime("%a")
- Gtoday = now.weekday()
- Htoday = datetime.get_day_name(now)
- IdaysLeft = 6 - now.weekday()
- JdaysLeft = 7 - now.weekday()
- KdaysLeft = 6 - datetime.datetime.weekday
- LdaysLeft = len(weekendSpecials)
26You need to test whether an object is an instance of a specific class.
Complete the code by selecting the correct option from each drop-down list.
import [blank_start]1[blank_end] unittest
class TestlsInstance [blank_start]2[blank_end]
def [blank_start]3[blank_end] (self):
[blank_start]4[blank_end]
if name == ' main_':
unittest.main()- Aimport
- Bfrom
- Cinclude
- Drequire
- Eunittest.TestCase
- Funittest
- GTestCase
- Hunittest.TestResult
- Itest_isInstance
- Jtest_isInstance(self)
- Kcheck_isInstance
- LisInstance
- Mself.assertIsInstance(obj, cls, msg=None
- Nunittest.assertIsInstance(obj, cls)
- Oself.isInstance(obj, cls)
- Pself.assertTrue(obj == cls)
Informationen
- Beschreibung
- Quiz am Python 2, erstellt von Lilian Sw am 05/07/2026.
- Autor
- Lilian Sw
- Sprache
- English
- Aufrufe
- 601
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz