diff --git a/projects/001-taxi-fare/python/main.py b/projects/001-taxi-fare/python/main.py index e69de29..fdd3204 100644 --- a/projects/001-taxi-fare/python/main.py +++ b/projects/001-taxi-fare/python/main.py @@ -0,0 +1,19 @@ +''' +In a particular jurisdiction, taxi fares consist of: +- base fare of €4.00, +- plus €0.25 for every 140 meters travelled. + +Write a function named **taxi fare** that takes the distance travelled (in kilometers) as its only parameter +and returns the total fare as its only result. +Write a main program that demonstrates the function. +''' + +def taxi_fare(kilometers): + addedtaxes = kilometers // 140 + taxfare = 0.25 * addedtaxes + totalfare = 4.00 + taxfare + return totalfare + +kilometers = int(input("Kilometers: ")) +totalfare = taxi_fare(kilometers) +print("Total fare = ", totalfare) \ No newline at end of file diff --git a/projects/002-shipping-calculator/python/main.py b/projects/002-shipping-calculator/python/main.py index e69de29..39f4aa0 100644 --- a/projects/002-shipping-calculator/python/main.py +++ b/projects/002-shipping-calculator/python/main.py @@ -0,0 +1,13 @@ +''' +An online retailer provides express shipping for many of its items at a rate of: +- €10.99 for the first item in an order +- €2.99 for each subsequent item in the same order. + +Write a function named **shipping calculator** that takes the number of items in the order as its **only parameter**. + +Return the shipping charge for the order as the function’s result. + +Include a main program that reads the number of items purchased from the user +and displays the shipping charge. +''' + diff --git a/projects/012-days-in-a-month/python/main.py b/projects/012-days-in-a-month/python/main.py index e69de29..7feaa65 100644 --- a/projects/012-days-in-a-month/python/main.py +++ b/projects/012-days-in-a-month/python/main.py @@ -0,0 +1,34 @@ +''' +Write a function called days in a month that determines how many days there are in a particular month. +Your function will take two parameters: + +the month as an integer between 1 and 12 +the year as a four digit integer +Ensure that your function reports the correct number of days in February for leap years. Include a main program that reads a month and year from the user and displays the number of days in that month. +''' + +def days_in_a_month(usermonth, useryear): + if useryear % 400 == 0 and useryear % 100 == 0: + totaldays = 366 + elif useryear % 100 != 0 and useryear % 4 == 0: + totaldays = 366 + else: totaldays = 365 + + if usermonth == 1 or 3 or 5 or 7 or 8 or 10 or 12: + daysinmonth = 31 + return daysinmonth + elif usermonth == 4 or 6 or 9 or 11: + daysinmonth = 30 + return daysinmonth + elif usermonth == 2: + if totaldays == 365: + daysinmonth = 28 + return daysinmonth + else: + daysinmonth = 29 + return daysinmonth + +usermonth = int(input("Please insert a month in integer: ")) +useryear = int(input("Please insert a 4-digit year: ")) +daysinmonth = days_in_a_month(usermonth, useryear) +print("The days in the month, and year, selected are: ", daysinmonth) \ No newline at end of file