Add 2020 Computer Science iGCSE Prerelease (India)

This commit is contained in:
2020-01-23 14:37:10 +00:00
parent 1502be18d8
commit 47c2ff8ba5

View File

@@ -1,4 +1,4 @@
def prerelease_047802(): def prerelease_047802_specimen():
# define lists for all required data # define lists for all required data
student_names = [] student_names = []
test_1_marks = [] test_1_marks = []
@@ -56,75 +56,150 @@ def prerelease_047802():
# print average total for all students # print average total for all students
print("Average total: %.2f" % (sum / 30)) print("Average total: %.2f" % (sum / 30))
def prerelease_047822(): def prerelease_047822_india_2020():
# ask which base model user wants
print("Which model?") print("Which model?")
print("(1) Hackback - Rs 5.35 Lakh") print("(1) Hackback - Rs 5.35 Lakh")
print("(2) Saloon - Rs 4.95 Lakh") print("(2) Saloon - Rs 4.95 Lakh")
print("(3) Estate - Rs 6.25 Lakh") print("(3) Estate - Rs 6.25 Lakh")
# keep asking until valid input is entered
model = None model = None
model = input()
while not model: while not model:
# ask for choice
model = input()
# if input isn't a number, display error
if (not model.isnumeric()): if (not model.isnumeric()):
model = input("Invalid input. Please enter a number between 1 and 3.") model = print("Invalid input. Please enter a number between 1 and 3.")
model = None model = None
# if input is a number outside valid range, display error
elif (int(model) < 1 or int(model) > 3): elif (int(model) < 1 or int(model) > 3):
model = input("Invalid input. Please enter a number between 1 and 3.") model = print("Invalid input. Please enter a number between 1 and 3.")
model = None model = None
# get cost of chosen base model
model_costs = [535000, 495000, 625000] model_costs = [535000, 495000, 625000]
cost = model_costs[int(model) - 1] cost = model_costs[int(model) - 1]
# ask which optional extras user wants
print("Optional extras:") print("Optional extras:")
print("(1) Set of luxury seats - Rs 45000") print("(1) Set of luxury seats - Rs 45000")
print("(2) Satellite navigation - Rs 5500") print("(2) Satellite navigation - Rs 5500")
print("(3) Parking sensors - Rs 10000") print("(3) Parking sensors - Rs 10000")
print("(4) Bluetooth connectivity - Rs 350") print("(4) Bluetooth connectivity - Rs 350")
print("(5) Sound system - Rs 1000") print("(5) Sound system - Rs 1000")
# ask for input, remove duplicated characters and remove non-numerical characters
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 "".join(set(input("Please enter the numbers of the optional extras you would like. Invalid options will be ignored: "))) if char.isdigit())
# remove numbers outside of valid range
optional_extras = "".join(char for char in optional_extras if 0 < char < 6) optional_extras = "".join(char for char in optional_extras if 0 < char < 6)
# add costs of chosen optional extras to total cost
optional_extra_costs = [45000, 5500, 1000, 350, 1000] optional_extra_costs = [45000, 5500, 1000, 350, 1000]
optional_extras_cost = 0
for number in optional_extras: for number in optional_extras:
cost += optional_extra_costs[int(number) - 1] cost += optional_extra_costs[int(number) - 1]
optional_extras_cost += optional_extra_costs[int(number) - 1]
# ask if user is an existing customer
existing_customer = input("Are you an existing customer (y/n)? ").lower() existing_customer = input("Are you an existing customer (y/n)? ").lower()
# evaluate input to boolean
existing_customer = True if (existing_customer[0] == "y" or existing_customer[-1] == "s") else False existing_customer = True if (existing_customer[0] == "y" or existing_customer[-1] == "s") else False
# ask if user has car to trade in
car_trade = input("Do you have a car to trade in (y/n)? ").lower() car_trade = input("Do you have a car to trade in (y/n)? ").lower()
# evaluate input to boolean
if (car_trade[0] == "y" or car_trade[-1] == "s"): if (car_trade[0] == "y" or car_trade[-1] == "s"):
car_trade = True car_trade = True
# keep asking for trade-in amount until valid input entered
trade_amount = None trade_amount = None
while (not trade_amount): while (not trade_amount):
# ask for input
trade_amount = input("How much have Snazzy Autos offered for your car (Rs)? ") trade_amount = input("How much have Snazzy Autos offered for your car (Rs)? ")
# if input isn't a number, display error
if (not trade_amount.isnumeric()): if (not trade_amount.isnumeric()):
print("Invalid input. Please enter a number.") print("Invalid input. Please enter a number.")
trade_amount = None trade_amount = None
# if input is a number outside of the acceptable range, display an error
elif (trade_amount <= 0): elif (trade_amount <= 0):
print("Invalid input. Please enter a number above 0.") print("Invalid input. Please enter a number above 0.")
trade_amount = None trade_amount = None
else: else:
car_trade = False car_trade = False
# display total cost without discounts
print("Cost: Rs %.2f" % cost) print("Cost: Rs %.2f" % cost)
# calculate discount: 10% if existing customer and 5% if car isn't being traded in
discount = (cost * 0.1 if existing_customer else 0) + (cost * 0.05 if not car_trade else 0) discount = (cost * 0.1 if existing_customer else 0) + (cost * 0.05 if not car_trade else 0)
# display total discount
print("Discount: Rs %.2f" % discount) print("Discount: Rs %.2f" % discount)
# if car is traded in, print trade-in amount
if car_trade: print("Trade-in amount: Rs %.2f" % trade_amount) if car_trade: print("Trade-in amount: Rs %.2f" % trade_amount)
# print total cost
print("\nTotal cost: Rs %.2f" % (cost - discount - trade_amount)) print("\nTotal cost: Rs %.2f" % (cost - discount - trade_amount))
# ask which payment option user wants
print("Which payment option would you like?") 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)) cashback = cost * 0.01
if (cashback > optional_extras_cost):
print("(1) Pay full amount now - 1% \cashback - total cost Rs %.2f - one payment - including cashback of Rs %.2f | or free optional extras - total cost %.2f - one payment - including discount of %.2f" % (cost * 0.99, cashback, cost - optional_extras_cost, optional_extras_cost))
else:
print("(1) Pay full amount now - free optional extras - total cost %.2f - one payment - including discount of %.2f | or 1% \cashback - total cost Rs %.2f - one payment - including cashback of Rs %.2f" % (cost - optional_extras_cost, optional_extras_cost, cost * 0.99, cashback))
print("(2) Monthly payements for four years - no charge - total cost Rs %.2f - payments of Rs %.2f - 48 payments" % (cost, cost / 48)) 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)) 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))
# keep asking until valid input entered
payment_option = None payment_option = None
while (not payment_option): while (not payment_option):
# ask for input
payment_option = input() payment_option = input()
# if input isn't a number, display error
if (not payment_option.isnumeric()): if (not payment_option.isnumeric()):
print("Invalid input. Please enter a number.") print("Invalid input. Please enter a number.")
payment_option = None payment_option = None
# if input is a number outside acceptable range, display error
elif (not 0 < int(payment_option) < 4): elif (not 0 < int(payment_option) < 4):
print("Invalid input. Please enter a number between 1 and 3.") print("Invalid input. Please enter a number between 1 and 3.")
payment_option = None payment_option = None
payment_option_costs = [-0.01, 0, 0.05] # calculate total cost, adjusted for chosen payment option
cost = cost * payment_option_costs[int(payment_option - 1)] if (payment_option == 3):
cost *= 1.05
prerelease_047802() # ask user if they want 1% cashback or free optional extras if they pay upfront
if (payment_option == 1):
print("Which option would you like?")
if (cashback > optional_extras_cost):
print("(1) Cashback - save Rs %.2f" % cashback)
print("(2) Free optional extras - save Rs %.2f" % optional_extras_cost)
else:
print("(1) Free optional extras - save Rs %.2f - total cost Rs %.2f" % (optional_extras_cost, cost - optional_extras_cost))
print("(2) Cashback - save Rs %.2f - total cost Rs %.2f" % (cashback, cost * 0.99))
# keep asking until valid input entered
cashback_or_free_extras = None
while (not cashback_or_free_extras):
cashback_or_free_extras = input()
# if input isn't a number, display error
if (not cashback_or_free_extras.isnumeric()):
print("Invalid input. Please enter a number.")
cashback_or_free_extras = None
# if input is number outside of acceptable range, display error
elif (not 0 < cashback_or_free_extras < 3):
print("Invalid input. Please enter either 1 or 2.")
cashback_or_free_extras = None
# calculate total cost and store order discount message
if ((cashback > optional_extras_cost and cashback_or_free_extras == 1) or (cashback <= optional_extras_cost and cashback_or_free_extras == 2)):
cost = cost * 0.99
order_message = "1% \cashback of Rs %.2f" % cashback
else:
cost = cost - optional_extras_cost
order_message = "free optional extras (Rs %.2f)" % optional_extras_cost
# store order discount message
if payment_option == 2:
order_message = "no discount"
elif payment_option == 3:
order_message = "5% price increase of Rs %.2f" % cost / 1.05 * 0.05
# print order summary
print("\nOrder summary:")
print("Total cost: Rs %.2f - with %s" % (cost, order_message))
payments_number = [1, 48, 80]
print("%d payment(s) of Rs %.2f" % (payments_number[payment_option], cost / payments_number[payment_option]))
prerelease_047802_specimen()