This commit is contained in:
Alex Hyett 2024-10-04 14:32:55 +01:00
parent 4eec2103f3
commit 606beb024f
7 changed files with 85 additions and 1 deletions

View file

@ -1,3 +1,6 @@
# beginner-coding-concepts
This is the code for my video on beginner coding concepts
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.

18
arrays.py Normal file
View file

@ -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)

18
for-loops.py Normal file
View file

@ -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)

17
functions.py Normal file
View file

@ -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)

12
if-statements.py Normal file
View file

@ -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")

11
variables.py Normal file
View file

@ -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)

5
while-loops.py Normal file
View file

@ -0,0 +1,5 @@
i = 1
while i <= 5:
print(i)
i = i + 1