Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions projects/001-taxi-fare/python/main.py
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions projects/002-shipping-calculator/python/main.py
Original file line number Diff line number Diff line change
@@ -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.
'''

34 changes: 34 additions & 0 deletions projects/012-days-in-a-month/python/main.py
Original file line number Diff line number Diff line change
@@ -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)