From 4c717f7730c7c859964e4262d3b674865d7fbc12 Mon Sep 17 00:00:00 2001 From: Martin Kinaro Date: Fri, 29 Jan 2021 12:23:52 +0300 Subject: [PATCH 1/4] week one bus fare challenge. --- challenges/week_1/bus_fare_challenge.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/challenges/week_1/bus_fare_challenge.py b/challenges/week_1/bus_fare_challenge.py index 0b90aa0..4f0d933 100644 --- a/challenges/week_1/bus_fare_challenge.py +++ b/challenges/week_1/bus_fare_challenge.py @@ -1 +1,23 @@ -# WRITE YOUR CODE SOLUTION HERE +from datetime import date + +date = date.today() + +day = date.strftime("%a") + +bus_fare = { + "Mon":100, + "Tue":100, + "Wen":100, + "Thur":100, + "Fri":100, + "Sat":60, + "Sun":80 +} +fare = None +if day in bus_fare: + print(date) + print(day) + fare = bus_fare[day] + print(fare) + + From ef7201cc537b22362f1f0176f84de986fa02085d Mon Sep 17 00:00:00 2001 From: Martin Kinaro Date: Fri, 29 Jan 2021 13:19:48 +0300 Subject: [PATCH 2/4] First week challenge: Bus fare challenge --- challenges/week_1/Readme.md | 8 ++++++++ challenges/week_1/bus_fare_challenge.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/challenges/week_1/Readme.md b/challenges/week_1/Readme.md index 430ab42..3846a5d 100644 --- a/challenges/week_1/Readme.md +++ b/challenges/week_1/Readme.md @@ -29,3 +29,11 @@ Run the [Checker](checker.py) file to evaluate your code. If all tests pass, you - `'fare'` *Failure to which all your tests will fail.* 3. The **Checker** file should **never** be **altered** at any cost. + + +Pseudo-code for the project + +Step 1: obtain the date today using the datetime module +step 2: obtain the day in the form of "Mon", "Tue" etc +step 3: make a list of busfares with an accompanying day +step 4: check if the day today is in the list of bus fares and then print the dates and fare. diff --git a/challenges/week_1/bus_fare_challenge.py b/challenges/week_1/bus_fare_challenge.py index 4f0d933..bf38a63 100644 --- a/challenges/week_1/bus_fare_challenge.py +++ b/challenges/week_1/bus_fare_challenge.py @@ -1,7 +1,8 @@ from datetime import date - +#initialize the date today date = date.today() +#obtain the day in the form "Mon", "Tue" etc. day = date.strftime("%a") bus_fare = { @@ -13,7 +14,9 @@ "Sat":60, "Sun":80 } +#initialize the fare variable fare = None +#check if the day is in the bus_fare dictionary if day in bus_fare: print(date) print(day) From 424b1cf65d858fdff9bd91c6c29a8b8a1f3bac48 Mon Sep 17 00:00:00 2001 From: Martin Kinaro Date: Fri, 5 Feb 2021 20:02:03 +0300 Subject: [PATCH 3/4] Week 2 challenge personal converter solution. --- challenges/week_2/personal_converter.py | 81 +++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 challenges/week_2/personal_converter.py diff --git a/challenges/week_2/personal_converter.py b/challenges/week_2/personal_converter.py new file mode 100644 index 0000000..8e153ed --- /dev/null +++ b/challenges/week_2/personal_converter.py @@ -0,0 +1,81 @@ +""" +Pseudo code for the challenge +1. create a converter function +2. Obtain the name of the user using the input function +3. print the name of the user with the choices to choose from +4. within the converter function specify the individual converter functions. +5. from the choice selected by user, run the corresponding converter function +6. Return the results to the user. +""" + +def converter(): + # ask the name input from the user + name = str(input("Input your name:")) + # print the name of the user and the hello message + print("Hello {}, welcome to your personal converter.".format(name)) + print("Please choose which conversion you would like to perform:") + print("1 - convert cm to inches\n2 - convert percent to letter grade\n3 - convert cups to ml\n4 - convert grams to ounces\n5 - convert fahrenheit to celsius\n") + # ask the user to choose the number for the choice + choice = int(input("Choice:")) + + # the function converting cm to inches + def cm_to_inch(): + num = int(input("Value in cm to convert: ")) + result = "{}cm = {}inches".format(num, num*0.39370) + print(result) + # function getting the percent and giving the respective letter grade + + def percent_to_letter_grade(): + num = float(input("Percent to convert to letter grade: ")) + num1 = int(num) + if num1 in range(80, 101, 1): + result = "A" + if num1 in range(70, 80, 1): + result = "B" + if num1 in range(60, 70, 1): + result = "C" + if num1 in range(50, 60, 1): + result = "D" + if num1 in range(40, 50, 1): + result = "E" + if num1 in range(30, 40, 1): + result = "F" + result = "{}% = {}".format(num, result) + print(result) + + # function changing cups to ml + def cups_to_ml(): + num = int(input("Enter the number of cups to convert: ")) + result = "{} cups = {} ml".format(num, num*250) + print(result) + + # functin changing grams to ounces + def grams_to_ounces(): + num = float( + input("Enter the number of grams to convert to ounces: ")) + result = "{} grams = {} ounces".format(num, num*0.0352) + print(result) + + # function changing farenheit to celcius + def farenheit_to_celcius(): + num = float(input("Value to convert Farenheit to Celcius: ")) + result = "{} Farenheit = {}\u00b0 C".format( + num, round((num-32)*5/9), 2) + print(result) + if choice == 1: + cm_to_inch() + elif choice == 2: + percent_to_letter_grade() + elif choice == 3: + cups_to_ml() + elif choice == 4: + grams_to_ounces() + elif choice == 5: + farenheit_to_celcius() + else: + print("The choice is not valid.") + return "Goodbye {}".format(name) + + +if __name__ == "__main__": + converter() From 614d3e8b82255fd585afd619263f54daac93433a Mon Sep 17 00:00:00 2001 From: Martin Kinaro Date: Fri, 5 Feb 2021 20:21:50 +0300 Subject: [PATCH 4/4] Week 2 personal converter challenge solution. --- challenges/week_2/personal_converter.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/challenges/week_2/personal_converter.py b/challenges/week_2/personal_converter.py index 8e153ed..772e0a7 100644 --- a/challenges/week_2/personal_converter.py +++ b/challenges/week_2/personal_converter.py @@ -36,10 +36,12 @@ def percent_to_letter_grade(): result = "C" if num1 in range(50, 60, 1): result = "D" - if num1 in range(40, 50, 1): + if num1 in range(20, 50, 1): result = "E" - if num1 in range(30, 40, 1): + if num1 in range(0, 40, 1): result = "F" + else: + print("Num not in required range") result = "{}% = {}".format(num, result) print(result)