01-Lab Work
1. Car Manufacturing
Cars and automobiles do not appear out of nowhere. How are they created from raw materials? Car factories! After design and engineering, different machines automate the process of creating parts of a car. This includes car doors, roofs, side frames, etc. These are then added to the main frame of a car. They are combined into a production line for assembly and further actions, such as painting.
In this lab, you will be working in the role of an IT intern in a car factory. Your manager, Sunny, has asked you to create programs to 1) calculate how much it would cost to produce a certain number of cars; and 2) calculate how long it would take to manufacture a certain number of cars.
You asked Sunny how this would help the factory and the work the company is doing. "It wouldn't, I'm just curious," he answered.
2. Task 1 - Calculating the Cost of Car Production
After gathering information about cars produced in your factory, Sunny told you that each car manufactured has:
- 4 car doors
- 4 wheels
- 4 tires
- 2 sets of lights
- 1 engine
- 1 steering wheel
Even though you know he definitely missed some parts, you decided to just go with it, and looked at the pricing of the car parts he provided:
| Car Part | Price ($) |
|---|---|
| A Car Door | 55.5 |
| A Car Wheel | 20 |
| A Tire | 15.3 |
| A Set of lights | 10.16 |
| An Engine | 150 |
| A Steering Wheel | 40 |
Complete the file cost.py, so that depending on the number of cars in the input, you would output the cost.
There are 3 parts to your task:
- Get the number of cars
- Calculate the total cost
- Print the total cost
An example, where the number 3 is the input:
Enter the number of cars: 3
The total cost will be: $1720.56Note: You must make sure that your output format is exactly the same as our given examples, so that you will not lose points in our auto-grading system, ZINC. The decimal places must be exactly the same as our given examples (which is 2 decimal places). You can always assume that the input will be a positive integer.
def main():
# The price of the car parts
car_door_cost: float = 55.5
car_wheel_cost: int = 20
tire_cost: float = 15.3
set_of_lights_cost: float = 10.16
engine_cost: int = 150
steering_wheel_cost: int = 40
prompt: str = "Enter the number of cars: "
# Task 1.1 Get the number of cars to produce/manufacture
# --- TODO below ---
# --- TODO above ---
# Task 1.2 Calculate the total cost
# --- TODO below ---
# --- TODO above ---
# Task 1.3 Print the total cost of car production
# Feel free to explore different print methods!
# --- TODO below ---
# --- TODO above ---
if __name__ == "__main__":
main()3. Task 2 - Calculate the Time Taken for Car Production
You really start to doubt Sunny's competence, as he is asking you to do tasks that make no sense. He has now given you the time needed to assemble each car part through the production line:
| Car Part | Time spent on Production Line (s) |
|---|---|
| A Car Door | 8 |
| A Car Wheel | 5.8 |
| A Tire | 5 |
| A Set of lights | 10.5 |
| An Engine | 20 |
| A Steering Wheel | 12.7 |
Sunny also tells you that for those parts with count > 1, e.g., car doors, they would be installed one by one. Now you (kind of) understand why management keeps complaining about inefficiency and wanting to replace workers with AI. He also mentioned that it would take an extra 30 seconds to spray paint the car, and it should be accounted for. You do not understand Sunny's line of thinking (if any), but you are tasked to complete time_taken.py.
Similar to the previous task, there are 3 parts to your task:
- Get the number of cars
- Calculate the total time taken
- Print the total time taken
An example, where the number 3 is the input:
Enter the number of cars: 3
The total time taken will be: 476.70 second(s)Note: Just like before, you must make sure that your output format is exactly the same as our given examples, so that you will not lose points in our auto-grading system, ZINC. The decimal places must be exactly the same as our given examples (which is 2 decimal places). You can always assume that the input will be a positive integer.
time_taken.py
def main():
# The time taken to assemble of the car parts
car_door_time: int = 8
car_wheel_time: float = 5.8
tire_time: int = 5
set_of_lights_time: float = 10.5
engine_time: int = 20
steering_wheel_time: float = 12.7
prompt: str = "Enter the number of cars: "
# Task 2.1 Get the number of cars to produce/manufacture
# --- TODO below ---
# --- TODO above ---
# Task 2.2 Calculate the total time
# --- TODO below ---
# --- TODO above ---
# Task 2.3 Print the total time of car production
# Feel free to explore different print methods!
# --- TODO below ---
# --- TODO above ---
if __name__ == "__main__":
main()4. Solution
def main():
# The price of the car parts
car_door_cost: float = 55.5
car_wheel_cost: int = 20
tire_cost: float = 15.3
set_of_lights_cost: float = 10.16
engine_cost: int = 150
steering_wheel_cost: int = 40
prompt: str = "Enter the number of cars: "
# Task 1.1 Get the number of cars to produce/manufacture
num_cars: int = int(input(prompt))
# Task 1.2 Calculate the total cost
cost_per_car: float = (
4 * car_door_cost
+ 4 * car_wheel_cost
+ 4 * tire_cost
+ 2 * set_of_lights_cost
+ 1 * engine_cost
+ 1 * steering_wheel_cost
)
total_cost: float = num_cars * cost_per_car
# Task 1.3 Print the total cost of car production
print(f"The total cost will be: ${total_cost:.2f}")
if __name__ == "__main__":
main()def main():
# The time taken to assemble of the car parts
car_door_time: int = 8
car_wheel_time: float = 5.8
tire_time: int = 5
set_of_lights_time: float = 10.5
engine_time: int = 20
steering_wheel_time: float = 12.7
prompt: str = "Enter the number of cars: "
# Task 2.1 Get the number of cars to produce/manufacture
num_cars: int = int(input(prompt))
# Task 2.2 Calculate the total time
time_per_car: float = (
4 * car_door_time
+ 4 * car_wheel_time
+ 4 * tire_time
+ 2 * set_of_lights_time
+ 1 * engine_time
+ 1 * steering_wheel_time
+ 30 # spray paint time
)
total_time: float = num_cars * time_per_car
# Task 2.3 Print the total time of car production
print(f"The total time taken will be: {total_time:.2f} second(s)")
if __name__ == "__main__":
main()def main():
# 定义每个零件的价格(根据题目表格)
car_door_cost: float = 55.5 # 每个车门的价格
car_wheel_cost: int = 20 # 每个车轮的价格
tire_cost: float = 15.3 # 每个轮胎的价格
set_of_lights_cost: float = 10.16 # 一套灯的价格
engine_cost: int = 150 # 一个发动机的价格
steering_wheel_cost: int = 40 # 一个方向盘的价格
# 输入提示
prompt: str = "Enter the number of cars: "
# === Task 1.1 获取用户输入 ===
# 输入的是需要生产的汽车数量
# int() 保证转换为整数类型
num_cars: int = int(input(prompt))
# === Task 1.2 计算总成本 ===
# 一辆车的总成本 = 各个零件单价 × 数量
cost_per_car: float = (
4 * car_door_cost # 4 个车门
+ 4 * car_wheel_cost # 4 个车轮
+ 4 * tire_cost # 4 个轮胎
+ 2 * set_of_lights_cost # 2 套灯
+ 1 * engine_cost # 1 个发动机
+ 1 * steering_wheel_cost# 1 个方向盘
)
# 总成本 = 单车成本 × 汽车数量
total_cost: float = num_cars * cost_per_car
# === Task 1.3 输出结果 ===
# f-string 格式化,保留两位小数
# 注意输出格式必须和题目完全一致,才能通过自动批改
print(f"The total cost will be: ${total_cost:.2f}")
# Python 程序入口:只有直接运行该文件时才会执行 main()
if __name__ == "__main__":
main()def main():
# 定义每个零件的组装时间(单位:秒)
car_door_time: int = 8 # 安装一个车门需要 8 秒
car_wheel_time: float = 5.8 # 安装一个车轮需要 5.8 秒
tire_time: int = 5 # 安装一个轮胎需要 5 秒
set_of_lights_time: float = 10.5 # 安装一套灯需要 10.5 秒
engine_time: int = 20 # 安装一个发动机需要 20 秒
steering_wheel_time: float = 12.7 # 安装一个方向盘需要 12.7 秒
# 输入提示
prompt: str = "Enter the number of cars: "
# === Task 2.1 获取用户输入 ===
# 输入需要生产的汽车数量
num_cars: int = int(input(prompt))
# === Task 2.2 计算总时间 ===
# 一辆车的组装总时间 = 零件安装时间 × 数量 + 额外喷漆时间
time_per_car: float = (
4 * car_door_time # 4 个车门
+ 4 * car_wheel_time # 4 个车轮
+ 4 * tire_time # 4 个轮胎
+ 2 * set_of_lights_time # 2 套灯
+ 1 * engine_time # 1 个发动机
+ 1 * steering_wheel_time # 1 个方向盘
+ 30 # 额外喷漆时间 30 秒
)
# 总时间 = 单车时间 × 汽车数量
total_time: float = num_cars * time_per_car
# === Task 2.3 输出结果 ===
# f-string 格式化,保留两位小数
# 输出格式严格要求:带单位 "second(s)"
print(f"The total time taken will be: {total_time:.2f} second(s)")
# Python 程序入口
if __name__ == "__main__":
main()def main():
# The price of the car parts
car_door_cost: float = 55.5
car_wheel_cost: int = 20
tire_cost: float = 15.3
set_of_lights_cost: float = 10.16
engine_cost: int = 150
steering_wheel_cost: int = 40
prompt: str = "Enter the number of cars: "
# Task 1.1 Get the number of cars to produce/manufacture
# --- TODO below ---
a = (int(input("The number of cars:")))
print(a)
# --- TODO above ---
# Task 1.2 Calculate the total cost
# --- TODO below ---
total_cost = a * (55.5 * 4 + 20 * 4 + 15.3 * 4 + 2 * 10.16 + 150 + 40)
# --- TODO above ---
# Task 1.3 Print the total cost of car production
# Feel free to explore different print methods!
# --- TODO below ---
print(total_cost)
# --- TODO above ---
if __name__ == "__main__":
main()def main():
# The time taken to assemble of the car parts
car_door_time: int = 8
car_wheel_time: float = 5.8
tire_time: int = 5
set_of_lights_time: float = 10.5
engine_time: int = 20
steering_wheel_time: float = 12.7
prompt: str = "Enter the number of cars: "
# Task 2.1 Get the number of cars to produce/manufacture
# --- TODO below ---
car_number = int(input(prompt))
print(car_number)
# --- TODO above ---
# Task 2.2 Calculate the total time
# --- TODO below ---
extra_time = 30
total_time = car_number * (
car_door_time * 4 + car_wheel_time * 4 + tire_time * 4 + set_of_lights_time * 2 + engine_time + steering_wheel_time + extra_time)
# --- TODO above ---
# Task 2.3 Print the total time of car production
# Feel free to explore different print methods!
# --- TODO below ---
print("{:.2f}second(s)".format(total_time))
# --- TODO above ---
if __name__ == "__main__":
main()5. 方便测试
🚗 1 辆车的成本 (cost)
- 4 × car_door_cost = 4 × 55.5 = 222.0
- 4 × car_wheel_cost = 4 × 20 = 80.0
- 4 × tire_cost = 4 × 15.3 = 61.2
- 2 × set_of_lights_cost = 2 × 10.16 = 20.32
- 1 × engine_cost = 150.0
- 1 × steering_wheel_cost = 40.0
合计 = 222.0 + 80.0 + 61.2 + 20.32 + 150.0 + 40.0 = 573.52
👉 所以 1 辆车成本:$573.52
⏱ 1 辆车的时间 (time)
- 4 × car_door_time = 4 × 8 = 32.0
- 4 × car_wheel_time = 4 × 5.8 = 23.2
- 4 × tire_time = 4 × 5 = 20.0
- 2 × set_of_lights_time = 2 × 10.5 = 21.0
- 1 × engine_time = 20.0
- 1 × steering_wheel_time = 12.7
- spray paint = 30.0
合计 = 32.0 + 23.2 + 20.0 + 21.0 + 20.0 + 12.7 + 30.0 = 158.9
👉 所以 1 辆车时间:158.90 second(s)
✅ 对照输出:
Enter the number of cars: 1
The total cost will be: $573.52
The total time taken will be: 158.90 second(s)公众号:AI悦创【二维码】

AI悦创·编程一对一
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,招收学员面向国内外,国外占 80%。全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh
C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh
方法一:QQ
方法二:微信:Jiabcdefh

更新日志
4385b-于556d1-于4ac6a-于f1a76-于0638d-于a44f6-于70353-于ae8a4-于9bfdc-于4d098-于1c35a-于cbb3a-于76989-于86c50-于027da-于