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/010-hexadecimal-and-decimal-digits/python/main.py b/projects/010-hexadecimal-and-decimal-digits/python/main.py index e69de29..b63e338 100644 --- a/projects/010-hexadecimal-and-decimal-digits/python/main.py +++ b/projects/010-hexadecimal-and-decimal-digits/python/main.py @@ -0,0 +1,26 @@ +''' +Write two functions, hex2int and int2hex, that convert between hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F) and decimal (base 10) integers. +The hex2int function is responsible for converting a string containing a single hexadecimal digit to a base 10 integer. +The int2hex function is responsible for converting an integer between 0 and 15 to a single hexadecimal digit. +Each function will take the value to convert as its only parameter and return the converted value as its only result. +Ensure that the hex2int function works correctly for both uppercase and lowercase letters. +Your functions should display a meaningful error message and end the program if the parameter’s value is outside the expected range. +''' + +def hex2int(initialvalue): + convertedvalue = int(initialvalue, 16) + return convertedvalue + +def int2hex(initialvalue): + newvalue = int(initialvalue) + convertedvalue = hex(newvalue) + return convertedvalue + +initialvalue = input("Please insert a value: ") +question = input("In which base do you want to convert the precedent string? (hex/dec)") +if question == "hex": + finalvalue = int2hex(initialvalue) + print("The initial value converted into hexadecimal is: ", finalvalue) +else: + finalvalue = hex2int(initialvalue) + print("The initial value converted into decimal is: ", finalvalue) \ No newline at end of file