wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PART1_M

Total questions: 40

Worksheet time: 32mins

Name
Class
Date
1.

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

What is the result?

a)

3

b)

13

c)

15

d)

69

2.

Northwind Traders has hired you as an intern on the coding team that creates e-commerce 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)  

3.

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)  

4.

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)

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

b)

Place the notes inside of parentheses on any line.

c)

Place the notes after the # sign on any line.

d)

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

5.

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)

from math import sqrt as squareRoot

b)

from math.sqrt as squareRoot

c)

import math.sqrt as squareRoot

d)

import sqrt from math as squareRoot

6.

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

The out.txt file does not exist. You run the code. The code will execute without error. Review the underlined text. If it makes the statement correct, select “No change is needed.” If the statement is incorrect, select the answer choice that makes the statement correct.

a)

No change is needed.

b)

The code runs, but generates a logic error.

c)

The code will generate a runtime error.

d)

The code will generate a syntax error.

7.

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.

Which code should you write for line O5 and line 06?

a)

05 if line != ‘‘:

06 if line !=””:

b)

05 if line != ‘\n’:

06 if line != None:

c)

05 if line != ‘\n’:

06 if line != “”:

d)

05 if line != ‘‘:

06 if line != “\n”:

8.

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

Which error exists in the code?

a)

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

b)

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

c)

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

d)

Line 05 causes a runtime error because the expression is incomplete

9.

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)

b)

c)

d)

10.

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)

name = input

b)

input(name)

c)

name = input()

d)

input(”name”)

11.

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)  

12.

You evaluate the following code:

What is the output of the print statement?

a)

4

b)

False

c)

True

d)

5

13.

A classmate has asked you to debug the following code:

What is the output that is printed to the screen?

a)

birthday

party

greeting

cake

b)

party

birthday

birthday

cake

c)

party

greeting

birthday

cake

d)

birthday

greeting

party

cake

14.

You write the following code:

You run the code. What is the output value?

(a)  

15.

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)

if not (minor and senior):

b)

if not (minor or senior):

c)

if (not minor) and senior:

d)

if (not minor) or senior:

16.

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)

colors[1:2]

b)

colors [::2]

c)

colors[2:2]

d)

colors [1::2]

17.

You write the following code:

You run the program. What is the output?

a)

2017--April--07

1,234,567.890

Press any key to continue...

b)

Apr--07--2017

1,234,567,8900

Press any key to continue...

c)

April--07--17

1,234,567.8900

Press any key to continue...

d)

April--07--17

1234567.89

Press any key to continue...

18.

You develop a Python application for your company. You have the following code. Line numbers are included for reference only.



(a)  

19.

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.



(a)  

20.

You find errors while evaluating the following code. Line numbers are included for reference only.



(a)  

21.

You are writing a program that calculates a user’s year of birth. The program asks users for their age and the current year, then outputs the user’s year of birth. You write the following code. Line numbers are included for reference only.



(a)  

22.

You write the following code:

(a)  

23.

You are writing a function that returns the data type of the value that is passed in. You write the following code. Line numbers are included for reference only.



(a)  

24.

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)

random.randrange()

b)

random.randrange(0.0, 1.0)

c)

random.random()

d)

random.randint(0, 1)

25.

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)

The path method does not exist in the os object.

b)

The path method does not exist in the os object.

c)

You need to import the os library.

d)

You need to import the os library.

26.

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)

employees[0:-4]

b)

employees [1:-5]

c)

employees [:-5]

d)

employees [0:-5]

e)

employees [1:-4]

27.

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)  

28.

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)

random.randint(5, 11)

b)

random.randrange(5, 12, 1)

c)

random.randint(5, 12)

d)

random.randrange(5, 11, 1)

29.

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)

math.ceil(x)

b)

math.fmod(x)

c)

math.floor(x)

d)

math.frexp(x)

e)

math.fabs(x)

30.

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)  

31.

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)
b)
c)

d)

32.

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)  

33.

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

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)  

34.

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)  

35.

You are developing a Python application for your company. You write the following code:



(a)  

36.

During school holidays, you volunteer to explain some basic programming concepts to your younger siblings.
You want to introduce the concept of data types in Python. You create the following three code segments:


(a)  

37.

You create a function to calculate the power of a number by using Python. You need to ensure that the function ¡s documented with comments. You create the following code. Line numbers are included for reference only.



(a)  

38.

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



(a)  

39.

You are writing a function that increments the player score in a game. The function has the following requirements: . If no value is specified for points, then points start at one . If bonus is True, then points must be doubled You write the following code. Line numbers are included for reference only.

TYPE Y OR N

(a)  

40.

You are creating a Python program that compares numbers. You create the following code. Line numbers are included for reference only. You need to ensure that the comparisons are accurate.

TYPE Y OR N

(a)