擅长:python、mysql、java
<p>您的类基本上应该是一些用于生成报价的参数的包装器。(作为一个简单的函数,它可能更合适,但我们将在这里使用它。)所有用户输入都将保持当前的方式,但速率的计算将在一个方法中完成。您将<em>使用</em>这个类,如下所示;我把实现这个类作为一个练习。你知道吗</p>
<pre><code>print("Hello")
print("Please enter your car insurance details:")
car_make = str(input("Enter your car make: "))
car_model = str(input("Enter your car model: "))
car_type = str(input("Is your car type \"Sport\" or \"Family: \""))
engine_size = float(input("Enter your engine size in litres: "))
years_claim_free = int(input("Enter Years you have been claim free: "))
q = Quote(small_engine=1.4, medium_engine=2.0, claim_free=10, starting_rate=300)
quote = q.generate_quote(car_make, car_model, car_type, engine_size, years_claim_free)
print("Your car insurance is €{}".format(quote))
</code></pre>
<p>(是否定义<code>generate_quote</code>采用品牌和型号取决于您自己;
当前脚本中没有使用它,但是<code>Quote</code>可能有其他方法
会利用这些信息。或者,启动速率可能是品牌和型号的函数,而不是单个参数。)</p>