From aa2911b5e72f7efd6fed4a4d2f1a70f4c56d72d9 Mon Sep 17 00:00:00 2001 From: BloodYce Date: Sun, 8 Sep 2024 11:12:38 +0200 Subject: [PATCH 1/2] solution-m4/001 --- projects/001-taxi-fare/python/main.py | 19 +++++++++++++++++++ .../002-shipping-calculator/python/main.py | 13 +++++++++++++ 2 files changed, 32 insertions(+) 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. +''' + From 6526c3bc842c9f6a8343fb4fee16841f959ec301 Mon Sep 17 00:00:00 2001 From: BloodYce Date: Wed, 25 Sep 2024 21:38:26 +0200 Subject: [PATCH 2/2] solution-m4/008 --- projects/008-random-password/python/main.py | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/projects/008-random-password/python/main.py b/projects/008-random-password/python/main.py index e69de29..de893a5 100644 --- a/projects/008-random-password/python/main.py +++ b/projects/008-random-password/python/main.py @@ -0,0 +1,28 @@ +''' +Write a function named random password that generates a random +password. + +The password should have a random length of between 7 and 10 +characters. +Each character should be randomly selected from positions 33 to 126 in +the ASCII table. +Your function will not take any parameters. +It will return the randomly generated password as its only result. +Display the randomly generated password in your file’s main program. +''' + +import random +import string + +def random_password(): + for n in range(lenght): + character = random.randrange(33,126) + asciichar = ''.join([chr(character)]) + lista.append(asciichar) + return lista + +lista = [] +lenght = random.randrange(7, 11) +listapassword = random_password() +passwordfinale = "".join(listapassword) +print("Password: ", passwordfinale) \ No newline at end of file