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.
'''

35 changes: 35 additions & 0 deletions projects/013-reduce-measures/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'''
Many recipe books still use cups, tablespoons and teaspoons to describe the volumes of ingredients used when cooking or baking.

While such recipes are easy enough to follow if you have the appropriate measuring cups and spoons, they can be difficult to double, triple or quadruple when cooking Christmas dinner for the entire extended family.

For example, a recipe that calls for 4 tablespoons of an ingredient requires 16 tablespoons when quadrupled.
However, 16 tablespoons would be better expressed (and easier to measure) as 1 cup.

Write a function named reduce measures that expresses an imperial volume using the largest units possible.
The function will take the number of units as its first parameter, and the unit of measure (cup, tablespoon or teaspoon) as its second parameter. It will return a string representing the measure using the largest possible units as its only result.

Example
units: 59
unit_measure: teaspoons
output: 1 cup, 3 tablespoons, 2 teaspoons
'''

def reduce_measures(userunits, userunitmeasure):
if userunitmeasure == "teaspoons":
teaspoons = userunits
print("Teaspoons: ", teaspoons)
elif userunitmeasure == "tablespoons":
tablespoons = userunits // 4
teaspoons = userunits - (4 * tablespoons)
print("Tablespoons: ", tablespoons, "teaspoons: ", teaspoons)
elif userunitmeasure == "cups":
cups = userunits // 16
newunits = userunits - (16 * cups)
tablespoons = newunits // 4
teaspoons = newunits - (4 * tablespoons)
print("Cups: ", cups, "tablespoons: ", tablespoons, "teaspoons: ", teaspoons)

userunits = int(input("Please input how many units you need to create: "))
userunitmeasure = str(input("Please input the unit measure you want to use (cups, tablespoons, teaspoons): "))
finalconversion = reduce_measures(userunits, userunitmeasure)