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:
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 05 and line 06?
Correct Answer:
B
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.
Solution:
References: https://www.python-course.eu/python3_formatted_output.php
Does this meet the goal?
Correct Answer:
A