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 53be72a87d16ff36f4b893070f5c56f34069bca6 Mon Sep 17 00:00:00 2001 From: BloodYce Date: Wed, 25 Sep 2024 21:39:17 +0200 Subject: [PATCH 2/2] solution-m4/009 --- .../009-password-validation/python/main.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/projects/009-password-validation/python/main.py b/projects/009-password-validation/python/main.py index e69de29..4123fff 100644 --- a/projects/009-password-validation/python/main.py +++ b/projects/009-password-validation/python/main.py @@ -0,0 +1,34 @@ +''' +In this exercise you will write a function named is valid password +that determines whether a password is good. +We will define a good password to be a one that is: + +at least 8 characters long +contains at least one uppercase letter +contains at least one lowercase letter +contains at least one number +Your function should return True if the password passed to it as its +only parameter is good. +Otherwise it should return False. + +Include a main program that reads a password from the user and reports +whether it is good. +Ensure that your main program only runs when your solution has not +been imported into another file. +''' + +def valid_password(userpassword, uppercase, lowercase, numbers): + if len(userpassword) >= 8 and uppercase in userpassword and lowercase in userpassword and numbers in userpassword: + return True + else: + return False + +userpassword = input("Please enter a password: ") +uppercase = "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" +lowercase = "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" +numbers = "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" +passwordcheck = valid_password(userpassword, uppercase, lowercase, numbers) +if passwordcheck == True: + print("The password inserted is correct!") +else: + print("The password inserted is WRONG!\nIt needs to contain at least one uppercase letter, at least one lowercase letter, at least one number and it should be at least 8 characters long!") \ No newline at end of file