forked from CoreyMSchafer/code_snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
950c294
commit 2165e57
Showing
13 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
|
||
condition = 'Test' | ||
|
||
if condition: | ||
print('Evaluated to True') | ||
else: | ||
print('Evaluated to False') |
This file contains 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 @@ | ||
|
||
# Comparisons: | ||
# Equal: == | ||
# Not Equal: != | ||
# Greater Than: > | ||
# Less Than: < | ||
# Greater or Equal: >= | ||
# Less or Equal: <= | ||
# Object Identity: is | ||
|
||
|
||
# False Values: | ||
# False | ||
# None | ||
# Zero of any numeric type | ||
# Any empty sequence. For example, '', (), []. | ||
# Any empty mapping. For example, {}. | ||
|
||
condition = False | ||
|
||
if condition: | ||
print('Evaluated to True') | ||
else: | ||
print('Evaluated to False') |
This file contains 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,5 @@ | ||
|
||
student = {'name': 'John', 'age': 25, 'courses': ['Math', 'CompSci']} | ||
|
||
for key, value in student.items(): | ||
print(key, value) |
This file contains 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,25 @@ | ||
|
||
# Number of days per month. First value placeholder for indexing purposes. | ||
month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | ||
|
||
|
||
def is_leap(year): | ||
"""Return True for leap years, False for non-leap years.""" | ||
|
||
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) | ||
|
||
|
||
def days_in_month(year, month): | ||
"""Return number of days in that month in that year.""" | ||
|
||
# year 2017 | ||
# month 2 | ||
if not 1 <= month <= 12: | ||
return 'Invalid Month' | ||
|
||
if month == 2 and is_leap(year): | ||
return 29 | ||
|
||
return month_days[month] | ||
|
||
print(days_in_month(2017, 2)) |
This file contains 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,21 @@ | ||
|
||
# Number of days per month. First value placeholder for indexing purposes. | ||
month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | ||
|
||
|
||
def is_leap(year): | ||
"""Return True for leap years, False for non-leap years.""" | ||
|
||
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) | ||
|
||
|
||
def days_in_month(year, month): | ||
"""Return number of days in that month in that year.""" | ||
|
||
if not 1 <= month <= 12: | ||
return 'Invalid Month' | ||
|
||
if month == 2 and is_leap(year): | ||
return 29 | ||
|
||
return month_days[month] |
This file contains 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,2 @@ | ||
|
||
courses = ['History', 'Math', 'Physics', 'CompSci'] |
This file contains 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,13 @@ | ||
|
||
print('Imported my_module...') | ||
|
||
test = 'Test String' | ||
|
||
|
||
def find_index(to_search, target): | ||
'''Find the index of a value in a sequence''' | ||
for i, value in enumerate(to_search): | ||
if value == target: | ||
return i | ||
|
||
return -1 |
This file contains 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 @@ | ||
|
||
num_1 = '100' | ||
num_2 = '200' | ||
|
||
num_1 = int(num_1) | ||
num_2 = int(num_2) | ||
|
||
print(num_1 + num_2) |
This file contains 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,18 @@ | ||
|
||
# Arithmetic Operators: | ||
# Addition: 3 + 2 | ||
# Subtraction: 3 - 2 | ||
# Multiplication: 3 * 2 | ||
# Division: 3 / 2 | ||
# Floor Division: 3 // 2 | ||
# Exponent: 3 ** 2 | ||
# Modulus: 3 % 2 | ||
|
||
|
||
# Comparisons: | ||
# Equal: 3 == 2 | ||
# Not Equal: 3 != 2 | ||
# Greater Than: 3 > 2 | ||
# Less Than: 3 < 2 | ||
# Greater or Equal: 3 >= 2 | ||
# Less or Equal: 3 <= 2 |
This file contains 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,12 @@ | ||
|
||
# Empty Lists | ||
empty_list = [] | ||
empty_list = list() | ||
|
||
# Empty Tuples | ||
empty_tuple = () | ||
empty_tuple = tuple() | ||
|
||
# Empty Sets | ||
empty_set = {} # This isn't right! It's a dict | ||
empty_set = set() |
This file contains 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,44 @@ | ||
|
||
|
||
# Mutable | ||
list_1 = ['History', 'Math', 'Physics', 'CompSci'] | ||
list_2 = list_1 | ||
|
||
print(list_1) | ||
print(list_2) | ||
|
||
# list_1[0] = 'Art' | ||
|
||
# print(list_1) | ||
# print(list_2) | ||
|
||
|
||
# Immutable | ||
# tuple_1 = ('History', 'Math', 'Physics', 'CompSci') | ||
# tuple_2 = tuple_1 | ||
|
||
# print(tuple_1) | ||
# print(tuple_2) | ||
|
||
# tuple_1[0] = 'Art' | ||
|
||
# print(tuple_1) | ||
# print(tuple_2) | ||
|
||
# Sets | ||
cs_courses = {'History', 'Math', 'Physics', 'CompSci'} | ||
|
||
print(cs_courses) | ||
|
||
|
||
# Empty Lists | ||
empty_list = [] | ||
empty_list = list() | ||
|
||
# Empty Tuples | ||
empty_tuple = () | ||
empty_tuple = tuple() | ||
|
||
# Empty Sets | ||
empty_set = {} # This isn't right! It's a dict | ||
empty_set = set() |
This file contains 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 @@ | ||
|
||
x = 0 | ||
|
||
while True: | ||
# if x == 5: | ||
# break | ||
print(x) | ||
x += 1 |
This file contains 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,5 @@ | ||
|
||
greeting = 'Hello' | ||
name = 'Michael' | ||
|
||
print(help(str.lower)) |