microsoft 98-381 practice test

Introduction to Programming Using Python

Last exam update: Sep 30 ,2024
Page 1 out of 3. Viewing questions 1-15 out of 43

Question 1

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 01
  • B. Line 02
  • C. Line 03
  • D. Line 04
  • E. Line 05
  • F. Line 06
  • G. Line 07
  • H. Line 08
Answer:

F G H

User Votes:
A
50%
B
50%
C
50%
D
50%
E
50%
F 1 votes
50%
G 1 votes
50%
H 1 votes
50%
Discussions
vote your answer:
A
B
C
D
E
F
G
H
0 / 1000

Question 2

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.
Hot Area:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-format.php#num

Discussions
0 / 1000

Question 3

HOTSPOT
The ABC company needs a way to find the count of particular letters in their publications to ensure that there is a good
balance. It seems that there have been complaints about overuse of the letter e. You need to create a function to meet the
requirements.
How should you complete this code? To answer, select the appropriate code segments in the answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-for-loop.php

Discussions
0 / 1000

Question 4

HOTSPOT
You are designing a decision structure to convert a students numeric grade to a letter grade. The program must assign a
letter grade as specified in the following table:

For example, if the user enters a 90, the output should be, Your letter grade is A. Likewise, if a user enters an 89, the
output should be Your letter grade is B.
How should you complete the code? To answer, select the appropriate code segments in the answer area.
Hot Area:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-if-else-statements.php

Discussions
0 / 1000

Question 5

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, 12)
  • B. random.randint(5, 11)
  • C. random.randrange(5, 12, 1)
  • D. random.randrange(5, 11, 1)
Answer:

B C


Explanation:
References:
https://docs.python.org/3/library/random.html#

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 6

HOTSPOT
You are writing a Python program to validate employee numbers.
The employee number must have the format ddd-dd-dddd and consist only of numbers and dashes. The program must print
True if the format is correct and print False if the format is incorrect.
How should you complete the code? To answer, select the appropriate code segments in the answer area.
Hot Area:

Answer:


Discussions
0 / 1000

Question 7

HOTSPOT
You are designing a decision structure to convert a students numeric grade to a letter grade. The program must assign a
letter grade as specified in the following table:

For example, if the user enters a 90, the output should be, Your letter grade is A. Likewise, if a user enters an 89, the
output should be Your letter grade is B.
How should you complete the code? To answer, select the appropriate code segments in the answer area.
Hot Area:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-if-else-statements.php

Discussions
0 / 1000

Question 8

HOTSPOT
The ABC Video company needs a way to determine the cost that a customer will pay for renting a DVD. The cost is
dependent on the time of day the DVD is returned. However, there are also special rates on Thursdays and Sundays. The
fee structure is shown in the following list:
The cost is $1.59 per night.

If the DVD is returned after 8 PM, the customer will be charged an extra day.

If the video is rented on a Sunday, the customer gets 30% off for as long as they keep the video.

If the video is rented on a Thursday, the customer gets 50% off for as long as they keep the video.

You need to write code to meet the requirements.
How should you complete the code? To answer, select the appropriate code segments in the answer area.
Hot Area:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-operators.php https://www.w3resource.com/python/python-if-else-
statements.php

Discussions
0 / 1000

Question 9

HOTSPOT
You are developing a Python application for an online product distribution company.
You need the program to iterate through a list of products and escape when a target product ID is found.
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.
Hot Area:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-while-loop.php

Discussions
0 / 1000

Question 10

DRAG DROP
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:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-data-type.php

Discussions
0 / 1000

Question 11

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 [1:-4]
  • B. employees [:-5]
  • C. employees [1:-5]
  • D. employees [0:-4]
  • E. employees [0:-5]
Answer:

B E


Explanation:
References:
https://www.w3resource.com/python/python-list.php#slice

User Votes:
A
50%
B
50%
C
50%
D
50%
E
50%
Discussions
vote your answer:
A
B
C
D
E
0 / 1000

Question 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. name = input
  • B. input(“name”)
  • C. input(name)
  • D. name = input()
Answer:

B

User Votes:
A
50%
B
50%
C
50%
D 1 votes
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000
rafisaiyari
2 months, 3 weeks ago

D. name = input()


Question 13

DRAG DROP
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.
Select and Place:

Answer:


Explanation:
References:
https://docs.python.org/3.1/tutorial/inputoutput.html https://stackoverflow.com/questions/11619942/print-series-of-prime-
numbers-in-python https://www.programiz.com/python-programming/examples/prime-number-intervals

Discussions
0 / 1000

Question 14

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

A


Explanation:
References:
https://docs.python.org/2/library/exceptions.html

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 15

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.
Hot Area:

Answer:


Explanation:
References:
https://www.w3resource.com/python/python-data-type.php

Discussions
0 / 1000
To page 2