## 98-381 : Introduction to Programming Using Python : Part 02

• 3
• 13
• 15
• 69

### Which two code segments should you use? Each correct answer presents a complete solution. (Choose two.)

• employees [1:-4]
• employees [:-5]
• employees [1:-5]
• employees [0:-4]
• employees [0:-5]
3. ### HOTSPOT

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.

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

• math.fmod(x)
• math.frexp(x)
• math.floor(x)
• math.ceil(x)
• math.fabs(x)

Explanation:

C: math.floor(x) returns the largest integer less than or equal to x.
E: math.fabs(x) returns the absolute value of x.

A: math.fmod() takes two variables
B: math.frexp(x) returns the mantissa and exponent of x as the pair (m, e). m is a float and e is an integer
D: math.ceil(x) returns the smallest integer greater than or equal to x

### Which code segment should you use?

• import math.sqrt as squareRoot
• import sqrt from math as squareRoot
• from math import sqrt as squareRoot
• from math.sqrt as squareRoot

### Which two functions should you use? Each correct answer presents a complete solution. (Choose two.)

• random.randint(5, 12)
• random.randint(5, 11)
• random.randrange(5, 12, 1)
• random.randrange(5, 11, 1)
7. ### DRAG DROP

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.

### Which code should you write at line 02?

• name = input
• input(“name”)
• input(name)
• name = input()

### Which code should you use?

• open(“local_data”, “r”)
• open(“local_data”, “r+”)
• open(“local_data”, “w+”)
• open(“local_data”, “w”)
Explanation:
Modes ‘r+’, ‘w+’ and ‘a+’ open the file for updating (reading and writing). Mode ‘w+’ truncates the file.
11. ### HOTSPOT

The ABC organics company needs a simple program that their call center will use to enter survey data for a new coffee variety.

The program must accept input and return the average rating based on a five-star scale. The output must be rounded to two decimal places.

You need to complete the code to meet the requirements.

How should you complete the code? To answer, select the appropriate code segments in the answer area.

NOTE: Each correct selection is worth one point.

12. ### HOTSPOT

The ABC company is building a basketball court for its employees to improve company morale.

You are creating a Python program that employees can use to keep track of their average score.

The program must allow users to enter their name and current scores. The program will output the user name and the user’s average score. The output must meet the following requirements:
The user name must be left-aligned.
If the user name has fewer than 20 characters, additional space must be added to the right.
The average score must have three places to the left of the decimal point and one place to the right of the decimal (XXX.X).

How should you complete the code? To answer, select the appropriate code segments in the answer area.

NOTE: Each correct selection is worth one point.

13. ### HOTSPOT

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? Use the drop-down menus to select the answer choice that answers each question based on the information presented in the code segment.

NOTE: Each correct selection is worth one point.

• Line 01
• Line 02
• Line 03
• Line 04
• Line 05
• Line 06
• Line 07
• Line 08

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

• No change is needed
• The code runs, but generates a logic error
• The code will generate a runtime error
• The code will generate a syntax error
16. ### HOTSPOT

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

17. ### HOTSPOT

You are developing a Python application for an online game.

You need to create a function that meets the following criteria:
– The function is named update_score
– The function receives the current score and a value
– The function adds the value to the current score
– The function returns the new score

How should you complete the code? To answer, select the appropriate code segments in the answer area.

### What should you do?

• Place the notes after the # sign on any line
• Place the notes after the last line of code separated by a blank line
• Place the notes before the first line of code separated by a blank line
• Place the notes inside of parentheses on any time

### Which code segments should you use for line 01 and line 04? Each correct answer presents part of the solution? (Choose two.)

• 01 def get_name():
• 01 def get_name(biker):
• 01 def get_name(name):
• 04 def calc_calories():
• 04 def calc_calories(miles, burn_rate):
• 04 def calc_calories(miles, calories_per_mile):
20. ### HOTSPOT

You create a function to calculate the power of a number by using Python.

You need to ensure that the function is documented with comments.

You create the following code. Line numbers are included for reference only.

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

Subscribe
Notify of