用python写出豪车,中档车,普通车的名字,等级,价格的范围
时间: 2024-04-29 16:21:25 浏览: 179
以下是一个简单的示例代码,其中包含豪车、中档车和普通车的名称、等级和价格范围:
```python
class Car:
def __init__(self, name, level, price_range):
self.name = name
self.level = level
self.price_range = price_range
luxury_cars = [
Car('Rolls-Royce', 'Luxury', '¥5 million+'),
Car('Bentley', 'Luxury', '¥2 million - ¥5 million'),
Car('Ferrari', 'Luxury', '¥2 million - ¥5 million'),
Car('Lamborghini', 'Luxury', '¥2 million - ¥5 million'),
]
midrange_cars = [
Car('BMW', 'Mid-range', '¥500,000 - ¥2 million'),
Car('Mercedes-Benz', 'Mid-range', '¥500,000 - ¥2 million'),
Car('Audi', 'Mid-range', '¥500,000 - ¥2 million'),
Car('Lexus', 'Mid-range', '¥500,000 - ¥2 million'),
]
ordinary_cars = [
Car('Toyota', 'Ordinary', '¥100,000 - ¥500,000'),
Car('Honda', 'Ordinary', '¥100,000 - ¥500,000'),
Car('Volkswagen', 'Ordinary', '¥100,000 - ¥500,000'),
Car('Ford', 'Ordinary', '¥100,000 - ¥500,000'),
]
for car in luxury_cars + midrange_cars + ordinary_cars:
print(f'{car.name} ({car.level}): {car.price_range}')
```
输出结果:
```
Rolls-Royce (Luxury): ¥5 million+
Bentley (Luxury): ¥2 million - ¥5 million
Ferrari (Luxury): ¥2 million - ¥5 million
Lamborghini (Luxury): ¥2 million - ¥5 million
BMW (Mid-range): ¥500,000 - ¥2 million
Mercedes-Benz (Mid-range): ¥500,000 - ¥2 million
Audi (Mid-range): ¥500,000 - ¥2 million
Lexus (Mid-range): ¥500,000 - ¥2 million
Toyota (Ordinary): ¥100,000 - ¥500,000
Honda (Ordinary): ¥100,000 - ¥500,000
Volkswagen (Ordinary): ¥100,000 - ¥500,000
Ford (Ordinary): ¥100,000 - ¥500,000
```
阅读全文