Two initial variables must be declared: one for a single fare price (fare) and another for the weekly fare price (weekFare).
For the purpose of this exercise, the constraints that 1<n<30 are specified. A while loop is used to check that the user value entered is greater than 1 and less than 30. If not, the user is prompted to enter a valid amount.
Once the user enters a valid number of subway rides taken per week, the function minsubcost computes the product of the individual fare cost and the number of rides taken with a local value (purchaseAmount=fare⋅n.
Using a boolean data type, the function compares the computed user amount with the price of a weekly fare. The Boolean value returns true if the purchased amount of subway rides is less than the price of a weekly fare and false otherwise.
In either case, the computation of their weekly expenditure is declared for the user to view.
If the Boolean variable returns true, the program prints a message telling the user that individual fares are more suited to their requirements.
If the Boolean variable returns false, the program prints the message explaining to the user that weekly fares are more monetarily beneficial for their requirements. If this is the case, the program computes the price the user pays per week on subway rides then subtracting the weekly fare amount from that value (fare⋅n−weekFare), shows the user how much they will save by purchasing a weekly fare.
fare=2.75weekFare=33defmin_sub_cost(n):purchaseAmount=n*farereturn(bool(purchaseAmount<weekFare))print("How many subway rides do you take over a 7 day period?")n=int(input())whilen<1orn>30:print("Please enter a number between 1 and 30. How many subway rides do you take over a 7 day period?")n=int(input())min_sub_cost(n)print("you spend $",n*fare,"per week on subway fares.")if(min_sub_cost(n)):print("You should use individual rides.")else:print("You should buy a weekly subway fare and save $",(n*fare)-weekFare)
How many subway rides do you take over a 7 day period?
This is more sophisticated that what I intended. Well presented. In the future, put the Jupyter notebook in the folder that contains the project prompt. 10/10