I'm new to this so I'm not sure if this is allowed but, I recently finished an assigned task and would like to know if there are any ways for me to improve my code.
My task is as follows: In preparation for the examination candidates should attempt the following practical tasks by writing and testing a program or programs.
The organiser of a senior citizens’ club arranges outings for the members. For each of these outings a coach is hired, meals at a restaurant are reserved and tickets for the theatre are booked. A program is required to work out the costs and provide a printed list showing everyone on the outing.
Write and test a program for the club organiser.
• Your program must include appropriate prompts for the entry of data. • Error messages and other output need to be set out clearly. • All variables, constants and other identifiers must have meaningful names.
You will need to complete these three tasks. Each task must be fully tested.
TASK 1 – Work out the total cost of the outing.
The organiser finds out how many senior citizens would be interested in the outing. The program for TASK 1 works out the cost from this information as seen from the table below.
$$ \begin{array}{|l|l|l|l|} \hline \text{Number of people}&\text{Hire of coach (\$)} &\text{Cost of a meal (\$)} &\text{Cost of a theatre ticket (\$)} \\ \hline 12-16 & 150 & 14.00 & 21.00 \\ \hline 17-26 & 190 & 13.50 & 20.00 \\ \hline 27-39 & 225 & 13.00 & 19.00 \\ \hline \end{array} $$
The minimum number of senior citizens needed for the outing to go ahead is 10; there cannot be more than 36 senior citizens on the outing. A minimum of two carers must go on the outing, with an additional carer needed if more than 24 senior citizens go on the outing. Carers do not have to pay anything for the outing. Work out the total cost and the cost per person for the senior citizens.
TASK 2 – Record who is going on the outing and how much has been paid.
Using your results from TASK 1, record the names of the people on the outing and the amount they have paid; include the carers on the outing. If there are spare places on the coach then extra people can be added; they are charged the same price as the other senior citizens. Calculate the total amount of money collected. Print out a list of the people on the outing.
TASK 3 – Identify the break-even point or profit that will be made on the outing.
Show whether the outing has made a profit or has broken even using the estimated cost from TASK 1 and the money collected from TASK 2.
And my code:
seniors = int(input("Please enter the amount of senior citizens going: "))
carers = int(input("Please enter the amount of carers going: "))
if seniors + carers >= int(40) or seniors <= int(1) or seniors >= int(37) or carers <= int(1) or (seniors >= int(24) and carers <= int(2)):
print("Enter Valid Info Please")
else:
print("Seniors going: " + repr(seniors) + " | Carers going: " + repr(carers))
if seniors >= int(1) and seniors <= int(16):
cost_coach = int(150)
cost_meal = int(14)
cost_ticket = int(21)
seats = int(16)
if seniors >= int(17) and seniors <= int(26):
cost_coach = int(190)
cost_meal = float(13.50)
cost_ticket = int(20)
seats = int(26)
if seniors >= int(27) and seniors <= int(36):
cost_coach = int(225)
cost_meal = int(13)
cost_ticket = int(19)
seats = int(36)
cost_coach_per_person = float(cost_coach / seniors)
rounded_cost_coach_per_person = float("%.2f" % cost_coach_per_person)
total_cost = (cost_meal * seniors) + (cost_ticket * seniors) + cost_coach
cost_per_person = cost_meal + cost_ticket + rounded_cost_coach_per_person
print("The total cost is $" + repr(total_cost))
print("The total cost per person is $" + repr(cost_per_person))
names_ppl_going = []
print("Logbook (Names and payment)")
n = int(1)
total_payment = float(0)
for x in range(seniors):
person_id = repr(n) + ")"
names_ppl_going.append(person_id)
name = input("[" + repr(n) + "] Enter a name: ")
name2 = name + ":"
names_ppl_going.append(name2)
payment = float("%.2f" %(float(input("Amount paid($): "))))
names_ppl_going.append("$" + repr(payment) + " | ")
total_payment += payment
n+=1
print("Whose going and how much they paid: ")
print(' '.join(names_ppl_going))
print("There are " + repr(seats - seniors) + " empty seats left")
question_3 = int(input("Would you like to fill the extra spaces? If so how many? (Number*/0 to cancel): "))
if question_3 > 0 and question_3 <= seats - seniors:
for x in range(question_3):
person_id = repr(n) + ")"
names_ppl_going.append(person_id)
name2 = input("[" + repr(n) + "] Enter a name: ") + ":"
names_ppl_going.append(name2)
names_ppl_going.append("$" + repr(float("%.2f" %(float(input("Amount paid($): "))))) + " | ")
total_payment += payment
n+=1
seniors += 1
print(' '.join(names_ppl_going))
else:
print("Process canceled")
while True:
question_1 = input("Do you still need to change anything in the list? (Y/N): ")
if question_1 == "Y":
question_2 = input("Would you like to change a name or a payment? (Name/Payment/Exit): ")
if question_2 == "Name":
list_change = int(input("Enter the number of the person you want to edit: "))
if list_change == int(1):
names_ppl_going.pop(1)
names_ppl_going = names_ppl_going[:int(list_change)] + [input("Enter the new name: ") + ":"] + names_ppl_going[int(list_change):]
print(' '.join(names_ppl_going))
elif list_change >= int(2):
list_change2 = (3*list_change)-2
names_ppl_going.pop(list_change2)
names_ppl_going = names_ppl_going[:int(list_change2)] + [input("Enter the new name: ") + ":"] + names_ppl_going[int(list_change2):]
print(' '.join(names_ppl_going))
elif question_2 == "Payment":
list_change = int(input("Enter the number of the person you want to edit: "))
if list_change == int(1):
convt = ((names_ppl_going[2]).strip('$')).strip(' | ')
total_payment -= float("%.2f" %(float(convt)))
names_ppl_going.pop(2)
payment_change = list_change + int(1)
payment_add = float("%.2f" %(float(input("Enter the new payment: "))))
total_payment += float(payment_add)
names_ppl_going = names_ppl_going[:int(payment_change)] + ["$" + repr(payment_add) + " | "] + names_ppl_going[int(payment_change):]
print(' '.join(names_ppl_going))
elif list_change >= int(2):
list_change2 = (3*list_change)-1
convt = ((names_ppl_going[list_change2]).strip('$')).strip(' | ')
total_payment -= float("%.2f" %(float(convt)))
names_ppl_going.pop(list_change2)
payment_add_2 = float("%.2f" %(float(input("Enter the new payment: "))))
total_payment += float(payment_add_2)
names_ppl_going = names_ppl_going[:int(list_change2)] + ["$" + repr(payment_add_2) + " | "] + names_ppl_going[int(list_change2):]
print(' '.join(names_ppl_going))
else:
break
else:
break
print("Total paid: $" + repr(float("%.2f" %(total_payment))))
if total_payment < total_cost:
print("You lost a total of $" + repr(total_cost - total_payment) + "!")
elif total_payment >= total_cost:
print("You earnt a profit of $" + repr(total_payment - total_cost))
print("There are " + repr(seats - seniors) + " empty seats left")
Thanks in advance!
seats - seniors
can't be right. \$\endgroup\$