Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tutorials/pandas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Pandas
38 changes: 38 additions & 0 deletions Tutorials/python/_01_getting-started/casting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Type casting

pi = 3.145

# type of pi
print('Type of pi: {}'.format(type(pi)))

# cast to string
pi_to_string = str(pi)
print('Type of pi: {}'.format(type(pi_to_string)))

# cast to int
pi_to_int = int(pi)
print('Type of pi: {}'.format(type(pi_to_int)))

# cast to boolean
pi_to_bool = bool(pi)
print('Type of pi: {}'.format(pi_to_bool))

print('-----------------------------')

year = '2025'

# type of year
print('Type of year: {}'.format(type(year)))

# cast to float
year_to_float = float(year)
print('Type of year: {}'.format(type(year_to_float)))

# cast to int
year_to_int = int(year)
print('Type of year: {}'.format(type(year_to_int)))

# cast to boolean
year_to_bool = bool(year)
print('Type of year: {}'.format(year_to_bool))

39 changes: 39 additions & 0 deletions Tutorials/python/_01_getting-started/operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Operators and operator precedence

# Arithmetic precedence rules - PEMDAS

# Without using parenthesis
expression_1 = 1 + 3 / 5 * 7 ** 2 - 10

# Using parenthesis
expression_2 = (1 + ((3 / 5) * (7 ** 2))) - 10

# Customizing output needs using parenthesis
salary = 7_000_000 # optional: use underscores '_' to separate digits, the output is not affected
tax = 0.2
bills = 0.1
savings = 0.3
expression_3 = salary - ((salary*tax) + (salary*bills) + (salary*savings))

# Results 1
print(f"Expression 1 solution: {expression_1}")
print(f"Expression 2 solution: {expression_2}")
print(f"Is expression 1 equivalent to expression 2: {expression_1 == expression_2}")
print(f"Is expression 1 the same as expression 2: {expression_1 is expression_2}")
print(f"Expression 3 custom solution: {expression_3}")

print('-----------------------------------')

# Boolean operations
# For and - both expressions are evaluated.
# For or - either one or both are evaluated, if the first one is True, the second is not evaluated.

expression_4 = ((3 * 2) == 6) and ((8 - 2) == 6)

# the second boolean expression is not evaluated, otherwise it would have thrown a ZeroDivisorError
expression_5 = ((5 - 5) == 0) or ((5 / 0) == 0)


# Results 2
print(f"Expression 4 solution: {expression_4}")
print(f"Expression 5 solution: {expression_5}")
24 changes: 24 additions & 0 deletions Tutorials/python/_01_getting-started/variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Using variables

name = 'Monty'
age = 75

# using string concatenation
message1 = 'My name is ' + name + '. I am ' + str(age) + ' years old.'

# using .format
message2 = 'My name is {}. I am {} years old.'.format(name, age)

# using a formated string (f-string)
message3 = f'My name is {name}. I am {age} years old.'

current_year = 2025

message4 = f'I was born in {current_year - age}.'

# print to standard output
print(message1)
print(message2)
print(message3)
print(message4)

8 changes: 8 additions & 0 deletions Tutorials/python/_02_control-flow/counting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Using a while loop

counter = 0

# print numbers 0 to 9
while counter < 10: # condition turns False when counter is 10
print(counter)
counter += 1 # increment counter by 1
7 changes: 7 additions & 0 deletions Tutorials/python/_02_control-flow/letters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Using a for loop

word = 'python'

# print each index and its corresponding letter in word
for letter in word:
print('Index: {} Letter: {}'.format(word.index(letter),letter))
16 changes: 16 additions & 0 deletions Tutorials/python/_02_control-flow/validate_age.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Using if-elif-else statements

age = int(input('Enter your age: '))


if not (age < 0): # Proceed as long as the age is a positive integer
if age <= 18:
print('Child.')
elif 18 < age <= 35:
print('Youth.')
elif 35 < age <= 150:
print('Mature.')
else:
print('A PRIME')
else:
print('Invalid age.')
11 changes: 11 additions & 0 deletions Tutorials/python/_03_functions/even.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# even number

def is_even(number: int):
return abs(number) % 2 == 0

counter = 0
for number in range(1452):
if is_even(number):
counter += 1

print("{} even numbers found.".format(counter))
11 changes: 11 additions & 0 deletions Tutorials/python/_03_functions/password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import random
import string

def generate_password(length:int = 16):
characters = string.ascii_letters + string.punctuation
new_password = ''
for character in characters:
new_password += random.choice(characters)
return new_password[:length]

print(generate_password())

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample password generation code for educational purposes only.