diff --git a/README.md b/README.md index 931cdb5..aa4e79d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # beginner-coding-concepts -This is the code for my video on beginner coding concepts \ No newline at end of file +This is the code for my video on [6 Coding Concepts You MUST Know For Beginners](https://youtu.be/pKFcVs2HibA). + +> [!NOTE] +> [This repository](https://code.alexhyett.com/alexhyett/beginner-coding-concepts) is also mirrored on [Codeberg.org](https://codeberg.org/alexhyett/beginner-coding-concepts) if you want to raise an issue. \ No newline at end of file diff --git a/arrays.py b/arrays.py new file mode 100644 index 0000000..078626c --- /dev/null +++ b/arrays.py @@ -0,0 +1,18 @@ +import datetime + +def calculate_age(dateOfBirth): + today = datetime.datetime.now() + age = today.year - dateOfBirth.year - ((today.month, today.day) < (dateOfBirth.month, dateOfBirth.day)) + return age + +def print_result(age): + if age >= 18: + print("You are " + str(age) + "! Enjoy the film") + else: + print("Sorry you aren't old enough you are only " + str(age)) + +datesOfBirth = [datetime.datetime(1995, 9, 20), datetime.datetime(1996, 12, 2)] +age = calculate_age(dateOfBirth) + +print_result(age) + diff --git a/for-loops.py b/for-loops.py new file mode 100644 index 0000000..080c794 --- /dev/null +++ b/for-loops.py @@ -0,0 +1,18 @@ +import datetime + +def calculate_age(dateOfBirth): + today = datetime.datetime.now() + age = today.year - dateOfBirth.year - ((today.month, today.day) < (dateOfBirth.month, dateOfBirth.day)) + return age + +def print_result(age): + if age >= 18: + print("You are " + str(age) + "! Enjoy the film") + else: + print("Sorry you aren't old enough you are only " + str(age)) + +datesOfBirth = [datetime.datetime(1995, 9, 20), datetime.datetime(1996, 12, 2)] + +for dateOfBirth in datesOfBirth: + age = calculate_age(dateOfBirth) + print_result(age) \ No newline at end of file diff --git a/functions.py b/functions.py new file mode 100644 index 0000000..8eae9d6 --- /dev/null +++ b/functions.py @@ -0,0 +1,17 @@ +import datetime + +def calculate_age(dateOfBirth): + today = datetime.datetime.now() + age = today.year - dateOfBirth.year - ((today.month, today.day) < (dateOfBirth.month, dateOfBirth.day)) + return age + +def print_result(age): + if age >= 18: + print("You are " + str(age) + "! Enjoy the film") + else: + print("Sorry you aren't old enough you are only " + str(age)) + +dateOfBirth = datetime.datetime(1995, 9, 20) +age = calculate_age(dateOfBirth) + +print_result(age) \ No newline at end of file diff --git a/if-statements.py b/if-statements.py new file mode 100644 index 0000000..fab6555 --- /dev/null +++ b/if-statements.py @@ -0,0 +1,12 @@ +import datetime + +dateOfBirth = datetime.datetime(1990, 9, 20) +today = datetime.datetime.now() + +age = today.year - dateOfBirth.year - ((today.month, today.day) < (dateOfBirth.month, dateOfBirth.day)) + +print(age) +if age >= 18: + print("Enjoy the film") +else: + print("Sorry you aren't old enough") \ No newline at end of file diff --git a/variables.py b/variables.py new file mode 100644 index 0000000..c7feb4b --- /dev/null +++ b/variables.py @@ -0,0 +1,11 @@ +import datetime + +def calculate_age(dateOfBirth): + today = datetime.datetime.now() + age = today.year - dateOfBirth.year - ((today.month, today.day) < (dateOfBirth.month, dateOfBirth.day)) + return age + +dateOfBirth = datetime.datetime(1990, 9, 20) +age = calculate_age(dateOfBirth) + +print(age) \ No newline at end of file diff --git a/while-loops.py b/while-loops.py new file mode 100644 index 0000000..7aea1c2 --- /dev/null +++ b/while-loops.py @@ -0,0 +1,5 @@ +i = 1 + +while i <= 5: + print(i) + i = i + 1 \ No newline at end of file