From e670a07b0a26cdf93fc4037799e8ace25741687e Mon Sep 17 00:00:00 2001 From: Timothy Wangwe Date: Wed, 6 Jan 2021 12:46:30 +0300 Subject: [PATCH 1/3] Create week 1 challenge --- challenges/week_1/bus_fare_challenge.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 challenges/week_1/bus_fare_challenge.py diff --git a/challenges/week_1/bus_fare_challenge.py b/challenges/week_1/bus_fare_challenge.py new file mode 100644 index 0000000..e971b5c --- /dev/null +++ b/challenges/week_1/bus_fare_challenge.py @@ -0,0 +1,16 @@ +# Write a program that does the following: +# - gets today's date and stores it in a variable 'date' +# - uses today's date to get the name on the day of the week written in short form with +# the first letter capitalized eg. 'Fri' if today were Friday +# - uses if statements to determine the today's fare following these bus fare schedule: +# - monday - friday --> 100 +# - saturday --> 60 +# - sunday --> 80 +# - Prints the results in this format +# Date: 2021-01-05 +# Day: Tue +# Fare: 100 +# NOTE THAT YOUR PROGRAM MUST MAKE USE OF THE VARIABLE NAME : 'date', 'day' and 'fare'. +# FAILURE TO WHICH ALL YOUR TESTS WILL FAIL. + +# WRITE YOUR CODE HERE From df020dcb34a88156ea17cc88eb32f9c35d48510a Mon Sep 17 00:00:00 2001 From: Timothy Wangwe Date: Wed, 6 Jan 2021 12:47:07 +0300 Subject: [PATCH 2/3] Checker for week 1 challenge --- challenges/week_1/checker.py | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 challenges/week_1/checker.py diff --git a/challenges/week_1/checker.py b/challenges/week_1/checker.py new file mode 100644 index 0000000..50020fc --- /dev/null +++ b/challenges/week_1/checker.py @@ -0,0 +1,55 @@ +import bus_fare_challenge +import datetime +import unittest + + +class TestBusFareChallenge(unittest.TestCase): + def setUp(self) -> None: + self.date = datetime.datetime.now().date() + self.day = self.date.strftime("%a") + self.charts = { + "Mon": 100, + "Tue": 100, + "Wed": 100, + "Thu": 100, + "Thu": 100, + "Sat": 60, + "Sun": 80, + } + + def test_date(self) -> None: + """ + Tests whether the date returned by the program is correct. + """ + actual = self.date + given = bus_fare_challenge.date + self.assertEqual(actual, given, f"Today's date is Wrong by {given - actual}!") + + def test_day(self) -> None: + """ + Tests whether the day returned by the program is correct. + """ + actual = self.day + given = bus_fare_challenge.day + self.assertEqual( + actual, given, f"Today is wrong, expexted {actual} but got {given}!" + ) + + def test_fare(self) -> None: + """ + Tests whether the fare returned by the program is correct. + """ + actual = self.charts[self.day] + given = bus_fare_challenge.fare + self.assertEqual( + actual, given, f"Fare is wrong, expected {actual} but got {given}!" + ) + + +if __name__ == "__main__": + print("=========================================================================") + print("=========================================================================") + print("===== Start: Checking Return Values For Today's Date, Day and Fare =====") + unittest.main(exit=False) + print("===== End: Checking Return Values For Today's Date, Day and Fare =======") + print("=========================================================================") From 966bb870411ecbe01f2220eca928f98e31ada344 Mon Sep 17 00:00:00 2001 From: Timothy Wangwe Date: Wed, 6 Jan 2021 16:26:52 +0300 Subject: [PATCH 3/3] Move instructions to readme file --- challenges/week_1/Readme.md | 31 +++++++++++++++++++++++++ challenges/week_1/bus_fare_challenge.py | 17 +------------- 2 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 challenges/week_1/Readme.md diff --git a/challenges/week_1/Readme.md b/challenges/week_1/Readme.md new file mode 100644 index 0000000..430ab42 --- /dev/null +++ b/challenges/week_1/Readme.md @@ -0,0 +1,31 @@ +# Bus Fare Challenge - Week 1 + +## Challenge + +Write a program that does the following: + +1. gets today's date and stores it in a variable `'date'` +2. uses today's date to get the name on the day of the week written in short form with the first letter capitalized eg. `'Fri'` if today were Friday and assigns it a variable `'day'` +3. uses if statements to determine the today's fare following these bus fare schedule: + + - monday - friday --> 100 + - saturday --> 60 + - sunday --> 80 +4. Prints the results in this format + >Date: 2021-01-05 + >Day: Tue + >Fare: 100 + +## Evaluation + +Run the [Checker](checker.py) file to evaluate your code. If all tests pass, your code will be the correct solution. If any fail, check the error messages and make changes to your code and repeat. + +## Note + +1. Your solution must be written in the [bus_fare_challenge](bus_fare_challenge.py) file and its name should never be changed. +2. Your program must make use of the following variable names: + - `'date'` + - `'day'` + - `'fare'` +*Failure to which all your tests will fail.* +3. The **Checker** file should **never** be **altered** at any cost. diff --git a/challenges/week_1/bus_fare_challenge.py b/challenges/week_1/bus_fare_challenge.py index e971b5c..0b90aa0 100644 --- a/challenges/week_1/bus_fare_challenge.py +++ b/challenges/week_1/bus_fare_challenge.py @@ -1,16 +1 @@ -# Write a program that does the following: -# - gets today's date and stores it in a variable 'date' -# - uses today's date to get the name on the day of the week written in short form with -# the first letter capitalized eg. 'Fri' if today were Friday -# - uses if statements to determine the today's fare following these bus fare schedule: -# - monday - friday --> 100 -# - saturday --> 60 -# - sunday --> 80 -# - Prints the results in this format -# Date: 2021-01-05 -# Day: Tue -# Fare: 100 -# NOTE THAT YOUR PROGRAM MUST MAKE USE OF THE VARIABLE NAME : 'date', 'day' and 'fare'. -# FAILURE TO WHICH ALL YOUR TESTS WILL FAIL. - -# WRITE YOUR CODE HERE +# WRITE YOUR CODE SOLUTION HERE