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/011-arbitrary-base-conversions/python/main.py b/projects/011-arbitrary-base-conversions/python/main.py index e69de29..27f9cdb 100644 --- a/projects/011-arbitrary-base-conversions/python/main.py +++ b/projects/011-arbitrary-base-conversions/python/main.py @@ -0,0 +1,45 @@ +''' +Write a program that allows the user to convert a number from one base to another. +Your program should support bases between 2 and 16 for both the input number and the result number. + +If the user chooses a base outside of this range then an appropriate error message should be displayed and the program should exit. + +Divide your program into several functions: + +a function named arbitrary to base 10 that converts from an arbitrary base to base 10 +a function that base 10 to arbitrary base converts from base 10 to an arbitrary base +a main program that reads the bases and input number from the user +''' + +def arbitrary(usernumber, userbase): + if userbase == "2": + convertedvalue = int(usernumber, 2) + return convertedvalue + elif userbase == "8": + convertedvalue = int(usernumber, 8) + return convertedvalue + elif userbase == "16": + convertedvalue = int(usernumber, 16) + return convertedvalue + else: + return userbase + +def arbitrary_base_converts(convertedvalue, basechoice): + if basechoice == "10": + return convertedvalue + elif basechoice == "2": + newvalue = bin(convertedvalue) + return newvalue + elif basechoice == "8": + newvalue = oct(convertedvalue) + return newvalue + elif basechoice == "16": + newvalue = hex(convertedvalue) + return newvalue + +usernumber = int(input("Please insert number: ")) +userbase = int(input("Please insert the base of the number: ")) +convertedvalue = arbitrary(usernumber, userbase) +basechoice = int(input("Please choose a base to convert the number into from 2, 8, 10, 16: ")) +finalvalue = arbitrary_base_converts(convertedvalue, basechoice) +print("Here's the number converted: ", finalvalue) \ No newline at end of file