-
Notifications
You must be signed in to change notification settings - Fork 6
Update #2 #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update #2 #27
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Pandas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
There was a problem hiding this comment.
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.