Add task 1 and task 2 of second prerelease

This commit is contained in:
2020-01-22 10:16:04 +00:00
parent e9e10dc95c
commit 1502be18d8

View File

@@ -56,4 +56,75 @@ def prerelease_047802():
# print average total for all students
print("Average total: %.2f" % (sum / 30))
def prerelease_047822():
print("Which model?")
print("(1) Hackback - Rs 5.35 Lakh")
print("(2) Saloon - Rs 4.95 Lakh")
print("(3) Estate - Rs 6.25 Lakh")
model = None
model = input()
while not model:
if (not model.isnumeric()):
model = input("Invalid input. Please enter a number between 1 and 3.")
model = None
elif (int(model) < 1 or int(model) > 3):
model = input("Invalid input. Please enter a number between 1 and 3.")
model = None
model_costs = [535000, 495000, 625000]
cost = model_costs[int(model) - 1]
print("Optional extras:")
print("(1) Set of luxury seats - Rs 45000")
print("(2) Satellite navigation - Rs 5500")
print("(3) Parking sensors - Rs 10000")
print("(4) Bluetooth connectivity - Rs 350")
print("(5) Sound system - Rs 1000")
optional_extras = "".join(char for char in "".join(set(input("Please enter the numbers of the optional extras you would like. Invalid options will be ignored: "))) if char.isdigit())
optional_extras = "".join(char for char in optional_extras if 0 < char < 6)
optional_extra_costs = [45000, 5500, 1000, 350, 1000]
for number in optional_extras:
cost += optional_extra_costs[int(number) - 1]
existing_customer = input("Are you an existing customer (y/n)? ").lower()
existing_customer = True if (existing_customer[0] == "y" or existing_customer[-1] == "s") else False
car_trade = input("Do you have a car to trade in (y/n)? ").lower()
if (car_trade[0] == "y" or car_trade[-1] == "s"):
car_trade = True
trade_amount = None
while (not trade_amount):
trade_amount = input("How much have Snazzy Autos offered for your car (Rs)? ")
if (not trade_amount.isnumeric()):
print("Invalid input. Please enter a number.")
trade_amount = None
elif (trade_amount <= 0):
print("Invalid input. Please enter a number above 0.")
trade_amount = None
else:
car_trade = False
print("Cost: Rs %.2f" % cost)
discount = (cost * 0.1 if existing_customer else 0) + (cost * 0.05 if not car_trade else 0)
print("Discount: Rs %.2f" % discount)
if car_trade: print("Trade-in amount: Rs %.2f" % trade_amount)
print("\nTotal cost: Rs %.2f" % (cost - discount - trade_amount))
print("Which payment option would you like?")
print("(1) Pay full amount now - 1% \cashback - total cost Rs %.2f - one payment - including cashback of Rs %.2f" % (cost * 1.01, cost * 0.01))
print("(2) Monthly payements for four years - no charge - total cost Rs %.2f - payments of Rs %.2f - 48 payments" % (cost, cost / 48))
print("(3) Monthly payments for seven years - 5% \charge - total cost Rs %.2f - payments of Rs %.2f - 80 payments" % (cost * 1.05, cost * 1.05 / 84))
payment_option = None
while (not payment_option):
payment_option = input()
if (not payment_option.isnumeric()):
print("Invalid input. Please enter a number.")
payment_option = None
elif (not 0 < int(payment_option) < 4):
print("Invalid input. Please enter a number between 1 and 3.")
payment_option = None
payment_option_costs = [-0.01, 0, 0.05]
cost = cost * payment_option_costs[int(payment_option - 1)]
prerelease_047802()