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

  1. Evaluate the following Python arithmetic expression:

    98-381 Part 02 Q01 028
    98-381 Part 02 Q01 028

    What is the result?

    • 3
    • 13
    • 15
    • 69
  2. 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.)

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

    98-381 Part 02 Q03 029 Question
    98-381 Part 02 Q03 029 Question
    98-381 Part 02 Q03 029 Answer
    98-381 Part 02 Q03 029 Answer
  4. 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.)

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

    Incorrect Answers:
    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

  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?

    • import math.sqrt as squareRoot
    • import sqrt from math as squareRoot
    • from math import sqrt as squareRoot
    • from math.sqrt as squareRoot
  6. 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.)

    • 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:

    98-381 Part 02 Q07 030
    98-381 Part 02 Q07 030

    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.

    98-381 Part 02 Q07 031 Question
    98-381 Part 02 Q07 031 Question
    98-381 Part 02 Q07 031 Answer
    98-381 Part 02 Q07 031 Answer
  8. 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:

    98-381 Part 02 Q08 032
    98-381 Part 02 Q08 032

    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.

    98-381 Part 02 Q08 033
    98-381 Part 02 Q08 033

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

    • 98-381 Part 02 Q08 034
      98-381 Part 02 Q08 034
    • 98-381 Part 02 Q08 035
      98-381 Part 02 Q08 035
    • 98-381 Part 02 Q08 036
      98-381 Part 02 Q08 036
    • 98-381 Part 02 Q08 037
      98-381 Part 02 Q08 037
  9. 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.

    98-381 Part 02 Q09 038
    98-381 Part 02 Q09 038

    Which code should you write at line 02?

    • name = input
    • input(“name”)
    • input(name)
    • name = input()
  10. 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?

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

    98-381 Part 02 Q11 039 Question
    98-381 Part 02 Q11 039 Question
    98-381 Part 02 Q11 039 Answer
    98-381 Part 02 Q11 039 Answer
  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.

    98-381 Part 02 Q12 040 Question
    98-381 Part 02 Q12 040 Question
    98-381 Part 02 Q12 040 Answer
    98-381 Part 02 Q12 040 Answer
  13. HOTSPOT

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

    98-381 Part 02 Q13 041
    98-381 Part 02 Q13 041

    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.

    98-381 Part 02 Q13 042 Question
    98-381 Part 02 Q13 042 Question
    98-381 Part 02 Q13 042 Answer
    98-381 Part 02 Q13 042 Answer
  14. 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.

    98-381 Part 02 Q14 043
    98-381 Part 02 Q14 043

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

    • Line 01
    • Line 02
    • Line 03
    • Line 04
    • Line 05
    • Line 06
    • Line 07
    • Line 08
  15. This question requires that you evaluate the underlined text to determine if it is correct.

    You write the following code:

    98-381 Part 02 Q15 044
    98-381 Part 02 Q15 044

    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.

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

    98-381 Part 02 Q16 045 Question
    98-381 Part 02 Q16 045 Question
    98-381 Part 02 Q16 045 Answer
    98-381 Part 02 Q16 045 Answer
  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.

    98-381 Part 02 Q17 046 Question
    98-381 Part 02 Q17 046 Question
    98-381 Part 02 Q17 046 Answer
    98-381 Part 02 Q17 046 Answer
  18. 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?

    • 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
  19. The ABC company 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.

    98-381 Part 02 Q19 047
    98-381 Part 02 Q19 047

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

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

    98-381 Part 02 Q20 048
    98-381 Part 02 Q20 048

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

    98-381 Part 02 Q20 049 Question
    98-381 Part 02 Q20 049 Question
    98-381 Part 02 Q20 049 Answer
    98-381 Part 02 Q20 049 Answer
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments