wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Practice 1

Total questions: 20

Worksheet time: 18mins

Name
Class
Date
1.

The ABC company 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)  

2.

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

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

(a)  

3.

The ABC company is converting an existing application to Python. You are creating documentation that will be used by several interns who are working on the team. You need to ensure that arithmetic expressions are coded correctly. What is the correct order of operations for the six classes of operations ordered from first to last in order of precedence? To answer, move all operations from the list of operations to the answer area and arrange them in the correct order.

(a)  

4.

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.

(a)  

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

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

(a)  

6.

You are writing a Python program to perform arithmetic operations. You create the following code

You are writing a Python program to perform arithmetic operations. You create the following code

a)

b)

c)

d)

7.

You 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.

You need to ensure that the result is correct. How should you complete the code on line 02?

(a)  

8.

Evaluate the following Python arithmetic expression:

(3*(1+2)**2 - (2**2)*3)

(a)  

9.

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)  

10.

You are an intern for ABC electric cars company. You must create a function that calculates the average velocity of their vehicles on a 1320 foot (1/4 mile) track. The output must be as precise as possible. How should you complete the code? To answer, select the appropriate code segments in the answer area.

(a)  

11.

You are creating a function that manipulates a number. The function has the following requirements:

Which two math functions should you use? Each correct answer is part of the solution. (Choose two.)

(a)  

12.

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)  

13.

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)  

14.

You are writing a function that works with files. You need to ensure that the function returns None if the file does not exist. If the file does exist, the function must return the first line. You write the following code:

In which order should you arrange the code segments to complete the function? To answer, move all code segments from the list of code segments to the answer area and arrange them in the correct order.

(a)  

15.

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:

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

a)

b)

c)

d)

16.

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)

input(name)

d)

name = input()

17.

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)  

18.

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)  

19.

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

20.

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 # sign on any line

b)

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

c)

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

d)

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