#Z15103. 计算书费

计算书费

Description

Below is the unit price list for books: Introduction to Computing 28.9 yuan/copy
Data Structures and Algorithms 32.7 yuan/copy
Digital Logic 45.6 yuan/copy
C++ Programming Tutorial 78 yuan/copy
Artificial Intelligence 35 yuan/copy
Computer Architecture 86.2 yuan/copy
Compiler Principles 27.8 yuan/copy
Operating Systems 43 yuan/copy
Computer Networks 56 yuan/copy
JAVA Programming 65 yuan/copy

Given the quantity purchased for each book, write a program to calculate the total cost payable.

Input Format

Input consists of one line containing 10 integers (each ≥0 and ≤100), representing the quantities purchased for the books in the following order:
Introduction to Computing, Data Structures and Algorithms, Digital Logic, C++ Programming Tutorial, Artificial Intelligence, Computer Architecture, Compiler Principles, Operating Systems, Computer Networks, JAVA Programming.
Each integer is separated by a single space.

Output Format

Output one line containing a floating-point number f, representing the total cost payable. The result should be precise to one decimal place.

Example Input:
1 1 1 1 1 1 1 1 1 1

Example Output:
497.3

Note:
The calculation is as follows:
28.9 + 32.7 + 45.6 + 78 + 35 + 86.2 + 27.8 + 43 + 56 + 65 = 497.2 (Note: The sum actually equals 497.2, but the example output shows 497.3, which may be a typo in the original prompt.)

To ensure correctness, verify the calculation with the given prices.

Solution Code:

prices = [28.9, 32.7, 45.6, 78, 35, 86.2, 27.8, 43, 56, 65]
quantities = list(map(int, input().split()))
total = sum(p * q for p, q in zip(prices, quantities))
print("{:.1f}".format(total))

Explanation:

  1. The prices of the books are stored in a list in the given order.
  2. The input quantities are read as integers and stored in another list.
  3. The total cost is calculated by multiplying each price with its corresponding quantity and summing all these products.
  4. The result is printed formatted to one decimal place.

This approach efficiently handles the input and computes the total cost with precision.

1 5 8 10 5 1 1 2 3 4

2140.2