wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PYTHON CERT REVIEWER

Total questions: 75

Worksheet time: 41mins

Name
Class
Date
1.

You are writing a Python program. The program collects customer data and stores it in a database.
The program handles a wide variety of data.
You need to ensure that the program handles the data correctly so that it can be stored in the database correctly.
Match the data type to the code segment. To answer, drag the appropriate data type from the column on the left to its code segment on the right. Each data type may be used once, more than once, or not at all.
Select and Place:

a)

bool,float,int,str,int

b)

bool,int,float,str,str

c)

int,bool,str,float,str

d)

int,bool,float,str,bool

2.

You are creating a Python program that shows a congratulation message to employees on their service anniversary.
You need to calculate the number of years of service and print a congratulatory message.
You have written the following code. Line numbers are included for reference only.

You need to complete the program.
Which code should you use at line 03?

a)

print("Congratulations on" + (int(end)-int(start)) + "years of service!")

b)

print("Congratulations on" + str(int(end)-int(start)) + "years of service!")

c)
  • print("Congratulations on" + int(end - start) + "years of service!")


d)
  • print("Congratulations on" + str(end - start)) + "years of service!")


3.

Evaluate the following Python arithmetic expression: (3*(1+2)**2 - (2**2)*3)

What is the result?

a)

A. 3

b)

B. 13

c)

C. 15

d)

D. 69

4.

Northwind Traders has hired you as an intern on the coding team that creates ecommerce applications. You must write a script that asks the user for a value. The value must be used as a whole number in a calculation, even if the user enters a decimal value. You need to write the code to meet the requirements. Which code segment should you use?

a)

A. totalltems = int(input(”How many items would you like?”))

b)

B. totalltems = str(input(”How many items would you like?”))

c)

C. totalltems = float(input(”How many items would you like?”))

d)

D. totalltems = input(”How many items would you like?”)

5.

You are creating a Python program that shows a congratulation message to employees on their service anniversary. You need to calculate the number of years of service and print a congratulatory message. You have written the following code. Line numbers are included for reference only.

01 start = input(”How old were you on your start date?)

02 end = input(’How old are you today?”)

03 You need to complete the program. Which code should you use at line 03?

a)

A. print(“congratulations on “ + int(end - start) + “ years of service!”)

b)

B. print(“congratulations on “ + (int(end) - int(start)) + “ years of service!”)

c)

C. print(“congratulations on “ + str(end - start) + “ years of service!”)

d)

D. print(”congratulations on “ + str(int(end) - int(start)) + “ years of service!”)

6.

You develop a Python application for your company. You want to add notes to your code so other team members will understand it

What should you do?

a)

A. Place the notes after the last line of code separated by a blank line.

b)

B. Place the notes inside of parentheses on any line.

c)

C. Place the notes after the # sign on any line.

d)

D. Place the notes before the first line of code separated by a blank line.

7.

You are writing an application that uses the sqrt function. The program must reference the function using the name squareRoot. You need to import the function. Which code segment should you use?

a)

A. from math import sqrt as squareRoot

b)

B. from math.sqrt as squareRoot

c)

C. import math.sqrt as squareRoot

d)

D. import sqrt from math as squareRoot

8.

This question requires that you evaluate the underlined text to determine if it is correct. You write the following code:

a)

A. No change is needed.

b)

B. The code runs, but generates a logic error.

c)

C. The code will generate a runtime error.

d)

D. The code will generate a syntax error.

9.

You are writing a Python program to automate inventory. Your first task is to read a file of inventory transactions. The file contains sales from the previous day, including the item id, price, and quantity. The following shows a sample of data from the file: 10, 200, 5 20, 100, 1 The code must meet the following requirements: . Each line of the file must be read and printed . If a blank line is encountered, it must be ignored . When all lines have been read, the file must be closed You create the following code. Line numbers are included for reference only.

a)

A. 05 if line != ‘‘:

06 if line !=””:

b)

B. 05 if line != ‘\n’: 06 if line != None:

c)

C. 05 if line != ‘\n’: 06 if line != “”:

d)

D. 05 if line != ‘‘:

06 if line != “\n”

10.

Tailspin Toys uses Python to control its new toy Happy Clown. The program has errors that cause the clown to run around in an infinite circle. You have been hired to help debug the following Happy Clown code. Line numbers are included for reference only.

a)

A. Line 05 has a syntax error because it should read (power == True).

b)

B. Line 08 has a syntax error because + = is an invalid statement.

c)

C. Line 07 causes a runtime error due to division by zero.

d)

D. Line 05 causes a runtime error because the expression is incomplete.

11.

Woodgrove Bank is migrating their legacy bank transaction code to Python. You have been hired to document the migrated code. Which documentation syntax is correct?

a)

A. Returns the current balance of the bank account

def get_balance(): return balance

b)

B. def get_balance(): /*Returns the current balance of the bank account*/

return balance

c)

C. //Returns the current balance of the bank account

def get_balance(): return balance

d)

D. def get_balance(): #Returns the current balance of the bank account

return balance

12.

You develop a Python application for your company. You need to accept input from the user and print that information to the user screen. You have started with the following code. Line numbers are included for reference only.

Which code should you write at line 02?

a)

A. name = input

b)

B. input(name)

c)

C. name = input()

d)

D. input(”name”)

13.

You develop a Python application for your school. You need to read and write data to a text file. If the file does not exist it must be created. If the file has content the content must be removed. Which code should you use?

a)

A. open(“local_data”, “r+”)

b)

B. open(“local_data”, “w+”)

c)

C. open(“local_data”, “r”)

d)

D. open(“local_data”, “w”)

14.

You evaluate the following code:

numList = [0,1,2,3,4]

print(5 in numList)

What is the output of the print statement?

a)

A. 4

b)

B. False

c)

C. True

d)

D. 5

15.

A classmate has asked you to debug the following code:

What is the output that is printed to the screen?

a)

A. birthday

party

greeting

cake

b)

B. party

birthday

birthday

cake

c)

C. party

greeting

birthday

cake

d)

D. birthday greeting

party

cake

16.

You write the following code:

list_1 = [1, 2]

list_2 = [3, 4]

list_3 = list_1 + list_2

list_4 = list_3 * 3

print(list_4)

You run the code. What is the output value?

a)

A. [3, 6, 9, 12]

b)

B. [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]

c)

C. [[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]]

d)

D. [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]

17.

You are writing a Python application for a dance studio. The studio wants to encourage youth and seniors to sign up. Minors and seniors must receive a 10% discount. You write the following code. Line numbers are included for reference only.

You need to complete the code. Which code should you add on line 03?

a)

A. if not (minor and senior):

b)

B. if not (minor or senior):

c)

C. if (not minor) and senior:

d)

D. if (not minor) or senior:

18.

You develop a Python application for your school. A list named colors contains 200 colors. You need to slice the list to display every other color starting with the second color. Which code should you use?

a)

A. colors[1:2]

b)

B. colors [::2]

c)

C. colors[2:2]

d)

D. colors [1::2]

19.

You run the program. What is the output?

a)

A. 2017--April--07 1,234,567.890 Press any key to continue...

b)

B. Apr--07--2017 1,234,567,8900 Press any key to continue...

c)

C. April--07--17 1,234,567.8900 Press any key to continue...

d)

D. April--07--17 1234567.89 Press any key to continue...

20.
  1. 1. Which part of the expression will be evaluated first?

  2. 2. Which operation will be evaluated second?

  3. 3. Which expression is equivalent to the expression in the function?

a)

1. c-d

2. addition

3. (a+b) * (c-d)

b)

1. b*c

  1. 2. addition

  2. 3. (a + (b*c)) – d

c)

1. b*c

2. subtraction

3. . a + ((b*c) – d)

d)

1. a+B

2. addition

3. a + ((b*c) – d)

21.

You create the following program to locate a conference room and display the room name. Line numbers are included for reference only. Colleagues report that the program sometimes produces incorrect results. You need to troubleshoot the program.

1. Which two data types are stored in the rooms list at line 01?

2. What is the data type of room at line 02?

3. Why does line 03 fail to find the rooms?

a)

1. float and int

2. int

3. Mismatched data type(s)

b)

1. float and bool

2. bool

3. Invalid syntax

c)

1. int and string

2. string

3. Mismatched data type(s)

d)

1. int and string

2. float

3. Misnamed variable(s)

22.

You find errors while evaluating the following code. Line numbers are included for reference only. You need to correct the code at line 03 and line 06. How should you correct the code?

1. Which code segment should you use at line 03?

2. Which code segment should you use at line 06?

a)

1. while(index < 10):

2.if numbers[index] == 6:

b)

1. while[index < 10]

2.if numbers[index] == 6

c)

1. while[index < 5] 2.if numbers(index) == 6:

d)

1. while[index < 5]

2.if numbers[index] == 6

23.

You need to ensure that the program uses the appropriate data types. What data types are used? Use the drop-down menus to select the answer choice that answers each question based on the information presented in ¡ne code segment.

1.What data type is age in line 01?

2.What data type is born in line 03?

3. What data type is message in line 04?

a)

1. float

2.str

3.float

b)

1. str

2.int

3.str

c)

1. int

2.float

3.bool

d)

1. str

2.float

3.bool

24.

1.What is displayed after the first print?

2.What is displayed after the second print?

3.What is displayed after the third print?

a)

1. Config2

2. Config1Config2

3. . Config1

b)

1. Config1

2. Config1Config2

3. . Config2

c)

1. Config1

2. Config1Config2

3. . Config1

d)

1. Config2

2. Config1

3. . Config1

25.

You are writing a function that returns the data type of the value that is passed in.

1.What is printed at line 04?

2.What is printed at line 05?

3.What is printed at line 06?

4.What is printed at line 07?

a)

1. <class ‘float’>

2.<class ‘bool’>

  1. 3.<class ‘int’>

  2. 4.<class ‘str’>

b)

1. <class ‘float’>

2.<class ‘bool’>

  1. 3.<class ‘str’>

  2. 4.<class ‘int’>

c)

1. <class ‘bool’>

2.<class ‘float’>

  1. 3.<class ‘int’>

  2. 4.<class ‘str’>

d)

1. <class ‘int’>

2.<class ‘str’>

  1. 3.<class ‘bool’>

  2. 4.<class ‘float’>

26.

You need to write code that generates a random float with a minimum value of 0.0 and a maximum value of 1.0. Which statement should you use?

a)

A. random.randrange()

b)

B. random.randrange(0.0, 1.0)

c)

C. random.random()

d)

D. random.randint(0, 1)

27.

You write a function that reads a data file and prints each line of the file. You write the following code. Line numbers are included for reference only.

When you run the program, you receive an error on line 03.

What is causing the error?

a)

A. The path method does not exist in the os object.

b)

B. The isfile method does not exist in the path object.

c)

C. You need to import the os library.

d)

D. The isfile method does not accept one parameter.

28.

You develop a Python application for your company. A list named employees contains 200 employee names, the last five being company management. You need to slice the list to display all employees excluding management. Which two code segments should you use? Each correct answer presents a complete solution. Choose two.

a)

A. employees[0:-4]

b)

B. employees [1:-5]

c)

C. employees [:-5]

d)

D. employees [0:-5]

e)

E. employees [1:-4]

29.

Adventure Works Cycles is creating a program that allows customers to log the number of miles biked. The program will send messages based on how many miles the customer logs. You create the following Python code. Line numbers are included for reference only.

You need to define the two required functions.

Which code segments should you use for line 01 and line 04?

Each correct answer presents part of the solution. Choose two.

a)

A. 01 def get_name():

b)

B. 01 def get_name(biker):

c)

C. 01 def get_name(name):

d)

D. 04 def calc_calories():

e)

E. 04 def calc_calories(miles, calories_per_mile):

30.

You are writing code that generates a random integer with a minimum value of 5 and a maximum value of 11. Which two functions should you use? Each correct answer presents a complete solution. Choose two.

a)

A. random.randint(5, 11)

b)

B. random.randrange(5, 12, 1)

c)

C. random.randint(5, 12)

d)

D. random.randrange(5, 11, 1)

31.

You are creating a function that manipulates a number. The function has the following requirements: . A float is passed into the function . The function must take the absolute value of the float . Any decimal points after the integer must be removed Which two math functions should you use? Each correct answer is part of the solution. Choose two.

a)

A. math.ceil(x)

b)

B. math.fmod(x)

c)

C. math.floor(x)

d)

D. math.frexp(x)

e)

E. math.fabs(x)

32.

Woodgrove Bank must generate a report that shows the average balance for all customers each day. The report must truncate the decimal portion of the balance. Which two code segments should you use? Each correct answer presents a complete solution. Choose two.

a)

A. average_balance = total_deposits**number_of_customers

b)

B. average_balance = total_deposits//number_of_customers

c)

C. average_balance = int(total_deposits/number_of_customers)

d)

D. average_balance = float(total_deposits//number_of_customers)

33.

You work on a team that is developing a game for AdventureWorks. You need to write code that generates a random number that meets the following requirements: . The number is a multiple of 5. . The lowest number is 5. . The highest number is 100. Which two code segments will meet the requirements? Each correct answer presents a complete solution. Choose two.

a)

A. from random import randrange print(randrange(5, 100, 5))

b)

B. from random import randint print(randint(1, 20) * 5)

c)

C. from random import randint print(randint(0, 20) * 5)

d)

D. from random import randrange print(randrange(0, 100, 5))

34.

You are creating a function that reads a data file and prints each line of the file. You write the following code. Line numbers are included for reference only. The code attempts to read the file even if the file does not exist. You need to correct the code. Which three lines have indentation problems? Each correct answer presents part of the solution. Choose three

a)

Line 04

b)

Line 05

c)

Line 06

d)

Line 07

e)

Line 08

35.

You are creating an ecommerce script that accepts input from the user and outputs the data in a comma delimited format. You write the following lines of code to accept input The output must meet the following requirements:

Strings must be enclosed inside of double-quotes .

Numbers must not be enclosed in quotes or other characters .

Each item must be separated with a comma

You need to complete the code to meet the requirements.

Which three code segments should you use? Each correct answer presents a complete solution. Choose three.

a)

A. print(’”{0}”,{1}’.format(item, sales))

b)

B. print(item + ‘,’ + sales)

c)

C. print(’”’ + item + ‘”,‘ + sa

d)

D. print(”{0},{1}”.format(item, sales))

e)

E. print(’”%s”, %s’ % (item, sales))

36.

You are building a Python program that displays all of the prime numbers from 2 to 100. How should you complete the code? To answer, drag the appropriate code segments to the correct location. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content. NOTE: Each correct selection is worth one point.

a)

A

b)

B

c)

C. break

d)

E. p = p + 1

e)

G

37.

For each of the following statements, select Yes if the statement is true. Otherwise, select No.

1.What is displayed after the first print?

2.What is displayed after the second print?

3.What is displayed after the third print?

4.What is displayed after the fourth print?

a)

1. NO

2. NO

3. YES

4.YES

b)

1. YES

2. NO

3. YES

4.YES

c)

1. NO

2. NO

3. NO

4.YES

d)

1. NO

2. YES

3. YES

4. NO

38.
a)

Yes, No, No

b)

Yes, Yes, No

c)

No, Yes, No

d)

Yes, No, Yes

39.
a)

Yes, No, Yes, No

b)

No, No, No, No

c)

Yes, No, No, Yes

d)

Yes, Yes, No, No

40.
a)

No, Yes, Yes, No

b)

Yes, Yes, Yes, No

c)

Yes, No, Yes, No

d)

Yes, Yes, Yes, Yes

41.
a)

No, Yes, No, No

b)

Yes, No, No, No

c)

Yes, Yes, No, No

d)

Yes, Yes, No, Yes

42.
a)

Yes, No, Yes, No

b)

No, No, Yes, Yes

c)

Yes, No, No, Yes

d)

Yes, No, Yes, Yes

43.
a)

BFED

b)

FDEB

c)

DEBF

d)

FBED

44.
a)

EDFCBA

b)

ABCFDE

c)

BCEDFCAB

d)

EDFABC

45.
a)

DABCE

b)

ABCDE

c)

CDABE

d)

EBCAD

46.
a)

EACDB

b)

ACDEB

c)

EDACB

d)

BEADC

47.
a)

AFCEB

b)

BAFCE

c)

FCEBA

d)

AFCBE

48.
a)

AGFE

b)

EFGA

c)

GFEA

d)

AFGE

49.
a)

BCA

b)

ABC

c)

CAB

50.
a)

BCBD

b)

BBCD

c)

ABCD

d)

CABC

51.
a)

ADCBC

b)

BCDCA

c)

ABBCD

d)

CDABC

52.
a)

CFHABD

b)

GEDFAC

c)

CFHBDA

d)

HFCBDA

53.
a)

AACB

b)

CBAA

c)

BACA

d)

CABA

54.
a)

ECC

b)

CAE

c)

ECA

d)

ACE

55.
a)

ABCD

b)

BDDD

c)

BCDD

d)

BDDA

56.
a)

BABA

b)

BAAB

c)

BBAA

d)

BAAA

57.
a)

ABCC

b)

ACBC

c)

ACCB

d)

AABC

58.
a)

ABCD

b)

BADC

c)

DABC

d)

DBCA

59.
a)

ACD

b)

CAD

c)

ADC

d)

ABD

60.
a)

BD

b)

CA

c)

AB

d)

DC

61.
a)

CB

b)

AB

c)

BC

d)

BA

62.
a)

BAB

b)

AAB

c)

BAA

d)

BBA

63.
a)

BAB

b)

BBA

c)

AAB

d)

ABC

64.
a)

ADB

b)

BDA

c)

BAD

d)

BCD

65.
a)

AB

b)

BD

c)

DB

d)

CD

66.
a)

DA

b)

BA

c)

BD

d)

BA

67.
a)

AC

b)

AB

c)

CD

d)

DF

68.
a)

AD

b)

DB

c)

DD

d)

CB

69.
a)

AC

b)

AA

c)

AB

d)

AD

70.
a)

DCAB

b)

DBCA

c)

DCBC

d)

DCBA

71.
a)

BAA

b)

ABA

c)

ABB

d)

AAB

72.
a)

BC

b)

AC

c)

DB

d)

BB

73.
a)

AC

b)

CB

c)

BC

d)

CD

74.
a)

ABC

b)

BCA

c)

BCB

d)

ABB

75.
a)

AB

b)

BB

c)

AC

d)

BD