├── 15 - Packages ├── requirements.txt ├── helpers.py ├── color_import_demo.py ├── import_module.py └── README.md ├── 12 - Loops ├── for.py ├── while.py ├── number.py └── README.md ├── 7 - Error handling ├── syntax.py ├── logic.py ├── runtime.py └── README.md ├── 2 - Print ├── hello_world.py ├── single_or_double_quotes.py ├── ask_for_input.py ├── print_blank_line.py ├── coding_challenge.py ├── README.md └── coding_challenge_solution.py ├── 3 - Comments ├── comments_for_debugging.py ├── comments_are_not_executed.py ├── string_in_double_quotes.py ├── README.md └── enable_pin.py ├── 5 - Numeric variables ├── print_pi.py ├── code_challenge.py ├── numbers_treated_as_strings.py ├── convert_strings_to_numbers_for_math.py ├── doing_math.py ├── combining_strings_and_numbers.py ├── README.md └── code_challenge_solution.py ├── Slides ├── 0 - Intro.pptx ├── 12 - Loops.pptx ├── 17 - JSON.pptx ├── 2 - Print.pptx ├── 6 - Dates.pptx ├── 3 - Comments.pptx ├── 13 - Functions.pptx ├── 16 - CallingAPI.pptx ├── 8 - Conditions.pptx ├── 11 - Collections.pptx ├── 7 - ErrorHandling.pptx ├── 1 - Getting started.pptx ├── 15 - ModulesPackages.pptx ├── 4 - StringVariables.pptx ├── 5 - NumericVariables.pptx ├── 9 - MultipleConditions.pptx ├── 14 - FunctionParameters.pptx └── 10 - ComplexConditionChecks.pptx ├── 11 - Collections ├── arrays.py ├── dictionaries.py ├── lists.py ├── common-operations.py ├── ranges.py └── README.md ├── 17 - JSON ├── TestImages │ ├── PolarBear.jpg │ ├── FeedingKangaroo.jpg │ └── Parliament_Hill.jpg ├── create_json_from_dict.py ├── create_json_with_nested_dict.py ├── create_json_with_list.py ├── readme.md ├── read_key_pair.py ├── read_subkey.py ├── read_key_pair_list.py └── read_json.py ├── 16 - Calling APIs ├── TestImages │ ├── PolarBear.jpg │ ├── FeedingKangaroo.jpg │ └── Parliament_Hill.jpg ├── readme.md ├── code_challenge.py └── call_api.py ├── 6 - Dates ├── code_challenge.py ├── get_current_date.py ├── date_functions.py ├── format_date.py ├── code_challenge_solution.py ├── README.md └── input_date.py ├── 4 - String variables ├── strings_in_variables.py ├── combine_strings.py ├── code_challenge.py ├── format_strings.py ├── code_challenge_solution.py ├── README.md └── string_functions.py ├── 8 - Handling conditions ├── add_else_different_indentation.py ├── comparing_strings.py ├── case_insensitive_comparisons.py ├── check_tax.py ├── code_challenge.py ├── add_else.py ├── code_challenge_solution.py └── README.md ├── 9 - Handling multiple conditions ├── use_elif.py ├── or_statements.py ├── multiple_if_statements.py ├── add_else_to_elif.py ├── nested_if.py ├── use_in_statements.py ├── code_challenge.py ├── README.md └── code_challenge_solution.py ├── 13 - Functions ├── print_time_repeated_code.py ├── print_time_function_different_messages.py ├── get_initials.py ├── README.md ├── print_time_function.py ├── print_time_function_fix_import.py ├── print_time_with_message_parameter.py ├── code_challenge.py ├── getting_clever_with_functions_harder_to_read.py ├── get_initails_function.py └── code_challenge_solution.py ├── 10 - Complex conditon checks ├── using_and.py ├── boolean_variables.py ├── readme.md ├── code_challenge.py └── code_challenge_solution.py ├── CODE_OF_CONDUCT.md ├── 18 - Decorators ├── creating_decorators.py └── README.md ├── 14 - Function parameters ├── get_initials_function.py ├── get_initials_multiple_parameters.py ├── code_challenge.py ├── get_initials_default_values.py ├── get_initials_named_parameters.py ├── code_challenge_solution.py ├── readme.md └── named_parameters_make_code_readable.py ├── LICENSE ├── .gitignore ├── SECURITY.md └── README.md /15 - Packages/requirements.txt: -------------------------------------------------------------------------------- 1 | colorama -------------------------------------------------------------------------------- /12 - Loops/for.py: -------------------------------------------------------------------------------- 1 | for name in ['Christopher', 'Susan']: 2 | print(name) 3 | -------------------------------------------------------------------------------- /7 - Error handling/syntax.py: -------------------------------------------------------------------------------- 1 | x = 42 2 | y = 206 3 | if x == y 4 | print('Success') -------------------------------------------------------------------------------- /2 - Print/hello_world.py: -------------------------------------------------------------------------------- 1 | # the print statement displays a message 2 | print('Hello world') 3 | -------------------------------------------------------------------------------- /3 - Comments/comments_for_debugging.py: -------------------------------------------------------------------------------- 1 | print('Hello world') 2 | print('It's a small world after all') 3 | -------------------------------------------------------------------------------- /5 - Numeric variables/print_pi.py: -------------------------------------------------------------------------------- 1 | # You can use variables to store numeric values 2 | pi = 3.14159 3 | print(pi) 4 | -------------------------------------------------------------------------------- /7 - Error handling/logic.py: -------------------------------------------------------------------------------- 1 | x = 206 2 | y = 42 3 | if x < y: 4 | print(str(x) + ' is greater than ' + str(y)) 5 | -------------------------------------------------------------------------------- /Slides/0 - Intro.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/0 - Intro.pptx -------------------------------------------------------------------------------- /Slides/12 - Loops.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/12 - Loops.pptx -------------------------------------------------------------------------------- /Slides/17 - JSON.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/17 - JSON.pptx -------------------------------------------------------------------------------- /Slides/2 - Print.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/2 - Print.pptx -------------------------------------------------------------------------------- /Slides/6 - Dates.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/6 - Dates.pptx -------------------------------------------------------------------------------- /Slides/3 - Comments.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/3 - Comments.pptx -------------------------------------------------------------------------------- /Slides/13 - Functions.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/13 - Functions.pptx -------------------------------------------------------------------------------- /Slides/16 - CallingAPI.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/16 - CallingAPI.pptx -------------------------------------------------------------------------------- /Slides/8 - Conditions.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/8 - Conditions.pptx -------------------------------------------------------------------------------- /Slides/11 - Collections.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/11 - Collections.pptx -------------------------------------------------------------------------------- /Slides/7 - ErrorHandling.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/7 - ErrorHandling.pptx -------------------------------------------------------------------------------- /11 - Collections/arrays.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | scores = array('d') 3 | scores.append(97) 4 | scores.append(98) 5 | print(scores) -------------------------------------------------------------------------------- /Slides/1 - Getting started.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/1 - Getting started.pptx -------------------------------------------------------------------------------- /Slides/15 - ModulesPackages.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/15 - ModulesPackages.pptx -------------------------------------------------------------------------------- /Slides/4 - StringVariables.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/4 - StringVariables.pptx -------------------------------------------------------------------------------- /Slides/5 - NumericVariables.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/5 - NumericVariables.pptx -------------------------------------------------------------------------------- /11 - Collections/dictionaries.py: -------------------------------------------------------------------------------- 1 | person = {'first': 'Christopher'} 2 | person['last'] = 'Harrison' 3 | print(person) 4 | print(person['first']) -------------------------------------------------------------------------------- /17 - JSON/TestImages/PolarBear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/17 - JSON/TestImages/PolarBear.jpg -------------------------------------------------------------------------------- /Slides/9 - MultipleConditions.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/9 - MultipleConditions.pptx -------------------------------------------------------------------------------- /15 - Packages/helpers.py: -------------------------------------------------------------------------------- 1 | def display(message, is_warning=False): 2 | if is_warning: 3 | print('Warning!!') 4 | print(message) 5 | -------------------------------------------------------------------------------- /Slides/14 - FunctionParameters.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/14 - FunctionParameters.pptx -------------------------------------------------------------------------------- /Slides/10 - ComplexConditionChecks.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/Slides/10 - ComplexConditionChecks.pptx -------------------------------------------------------------------------------- /11 - Collections/lists.py: -------------------------------------------------------------------------------- 1 | names = ['Christopher', 'Susan'] 2 | scores = [] 3 | scores.append(98) 4 | scores.append(99) 5 | print(names) 6 | print(scores) 7 | -------------------------------------------------------------------------------- /16 - Calling APIs/TestImages/PolarBear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/16 - Calling APIs/TestImages/PolarBear.jpg -------------------------------------------------------------------------------- /17 - JSON/TestImages/FeedingKangaroo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/17 - JSON/TestImages/FeedingKangaroo.jpg -------------------------------------------------------------------------------- /17 - JSON/TestImages/Parliament_Hill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/17 - JSON/TestImages/Parliament_Hill.jpg -------------------------------------------------------------------------------- /6 - Dates/code_challenge.py: -------------------------------------------------------------------------------- 1 | # print today's date 2 | # print yesterday's date 3 | # ask a user to enter a date 4 | # print the date one week from the date entered -------------------------------------------------------------------------------- /16 - Calling APIs/TestImages/FeedingKangaroo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/16 - Calling APIs/TestImages/FeedingKangaroo.jpg -------------------------------------------------------------------------------- /16 - Calling APIs/TestImages/Parliament_Hill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Agent00049/c9-python-getting-started/master/16 - Calling APIs/TestImages/Parliament_Hill.jpg -------------------------------------------------------------------------------- /12 - Loops/while.py: -------------------------------------------------------------------------------- 1 | names = ['Christopher', 'Susan'] 2 | index = 0 3 | while index < len(names): 4 | print(names[index]) 5 | # Change the condition!! 6 | index = index + 1 7 | -------------------------------------------------------------------------------- /3 - Comments/comments_are_not_executed.py: -------------------------------------------------------------------------------- 1 | # This is a comment in my code it does nothing 2 | # print('Hello world') 3 | # print("Hello world") 4 | # No output will be displayed! 5 | -------------------------------------------------------------------------------- /3 - Comments/string_in_double_quotes.py: -------------------------------------------------------------------------------- 1 | # Using double quotes for this string because 2 | # the string itself contains a single quote 3 | print("It's a small world after all") 4 | -------------------------------------------------------------------------------- /11 - Collections/common-operations.py: -------------------------------------------------------------------------------- 1 | names = ['Christopher', 'Susan'] 2 | print(len(names)) # Get the number of items 3 | names.insert(0, 'Bill') # Insert before index 4 | print(names) 5 | -------------------------------------------------------------------------------- /4 - String variables/strings_in_variables.py: -------------------------------------------------------------------------------- 1 | # You can store strings in variables 2 | first_name = 'Susan' 3 | 4 | # The variable can then be used later in your code 5 | print(first_name) 6 | -------------------------------------------------------------------------------- /2 - Print/single_or_double_quotes.py: -------------------------------------------------------------------------------- 1 | # Strings can be enclosed in single quotes 2 | print('Hello world single quotes') 3 | 4 | # Strings can also be enclosed in double quotes 5 | print("Hello world double quotes") 6 | -------------------------------------------------------------------------------- /11 - Collections/ranges.py: -------------------------------------------------------------------------------- 1 | names = ['Susan', 'Christopher', 'Bill'] 2 | presenters = names[0:2] # Get the first two items 3 | # Starting index and number of items to retrieve 4 | 5 | print(names) 6 | print(presenters) 7 | -------------------------------------------------------------------------------- /12 - Loops/number.py: -------------------------------------------------------------------------------- 1 | # range creates an array 2 | # First parameter is the starter 3 | # Second indicates the number of numbers to create 4 | # range(0, 2) creates [0, 1] 5 | for index in range(0, 2): 6 | print(index) 7 | -------------------------------------------------------------------------------- /2 - Print/ask_for_input.py: -------------------------------------------------------------------------------- 1 | # The input funciton allows you to prompt the user for a value 2 | # You need to declare a variable to hold the value entered by the user 3 | name = input('What is your name? ') 4 | 5 | print(name) -------------------------------------------------------------------------------- /8 - Handling conditions/add_else_different_indentation.py: -------------------------------------------------------------------------------- 1 | price = 5.0 2 | if price >= 1.00: 3 | tax = .07 4 | else: 5 | tax = 0 6 | # the print statement below is not indented so is executed after the if 7 | # statement is evaluated 8 | print(tax) 9 | -------------------------------------------------------------------------------- /9 - Handling multiple conditions/use_elif.py: -------------------------------------------------------------------------------- 1 | province = input("What province do you live in? ") 2 | tax = 0 3 | if province == 'Alberta': 4 | tax = 0.05 5 | elif province == 'Nunavut': 6 | tax = 0.05 7 | elif province == 'Ontario': 8 | tax = 0.13 9 | print(tax) -------------------------------------------------------------------------------- /3 - Comments/README.md: -------------------------------------------------------------------------------- 1 | # Comments 2 | 3 | Comments start with a hash character (#) and allow you to document your code. 4 | Comments are ignored when code is executed. 5 | 6 | - [Comments](https://docs.python.org/3/reference/lexical_analysis.html?highlight=comment) 7 | -------------------------------------------------------------------------------- /9 - Handling multiple conditions/or_statements.py: -------------------------------------------------------------------------------- 1 | province = input("What province do you live in? ") 2 | tax = 0 3 | if province == 'Alberta' \ 4 | or province == 'Nunavut': 5 | tax = 0.05 6 | elif province == 'Ontario': 7 | tax = 0.13 8 | else: 9 | tax = 0.15 10 | print(tax) 11 | -------------------------------------------------------------------------------- /9 - Handling multiple conditions/multiple_if_statements.py: -------------------------------------------------------------------------------- 1 | 2 | province = input("What province do you live in? ") 3 | tax = 0 4 | 5 | if province == 'Alberta': 6 | tax = 0.05 7 | if province == 'Nunavut': 8 | tax = 0.05 9 | if province == 'Ontario': 10 | tax = 0.13 11 | print(tax) 12 | -------------------------------------------------------------------------------- /15 - Packages/color_import_demo.py: -------------------------------------------------------------------------------- 1 | import colorama 2 | 3 | colorama.init() 4 | print(colorama.Fore.RED + 'This is red') 5 | 6 | from colorama import * 7 | 8 | init() 9 | print(Fore.BLUE + 'This is blue') 10 | 11 | from colorama import init, Fore 12 | print(Fore.GREEN + 'This is green') 13 | -------------------------------------------------------------------------------- /5 - Numeric variables/code_challenge.py: -------------------------------------------------------------------------------- 1 | # Ask a user to enter a number 2 | # Ask a user to enter a second number 3 | # Calculate the total of the two numbers added together 4 | # Print 'first number + second number = answer' 5 | # For example if someone enters 4 and 6 the output should read 6 | # 4 + 6 = 10 7 | -------------------------------------------------------------------------------- /9 - Handling multiple conditions/add_else_to_elif.py: -------------------------------------------------------------------------------- 1 | province = input("What province do you live in? ") 2 | tax = 0 3 | 4 | if province == 'Alberta': 5 | tax = 0.05 6 | elif province == 'Nunavut': 7 | tax = 0.05 8 | elif province == 'Ontario': 9 | tax = 0.13 10 | else: 11 | tax = 0.15 12 | print(tax) -------------------------------------------------------------------------------- /8 - Handling conditions/comparing_strings.py: -------------------------------------------------------------------------------- 1 | country = input('Enter the name of your home country: ') 2 | if country == 'canada': 3 | # string comparisons are case sensitive 4 | # if you typed in CANADA or Canada it will not match 5 | print('So you must like hockey!') 6 | else: 7 | print('You are not from Canada') 8 | -------------------------------------------------------------------------------- /4 - String variables/combine_strings.py: -------------------------------------------------------------------------------- 1 | # You can use the + operator to concatenate strings 2 | first_name = 'Susan' 3 | last_name = 'Ibach' 4 | print(first_name + last_name) 5 | 6 | # If you want a space between the strings you must include the space 7 | # within the string 8 | print('Hello ' + first_name + ' ' + last_name) 9 | -------------------------------------------------------------------------------- /7 - Error handling/runtime.py: -------------------------------------------------------------------------------- 1 | x = 42 2 | y = 0 3 | try: 4 | print(x / y) 5 | except ZeroDivisionError as e: 6 | # Optionally, log e somewhere 7 | print('Sorry, something went wrong') 8 | except: 9 | print('Something really went wrong') 10 | finally: 11 | print('This always runs on success or failure') 12 | -------------------------------------------------------------------------------- /15 - Packages/import_module.py: -------------------------------------------------------------------------------- 1 | # import module as namespace 2 | import helpers 3 | helpers.display('Not a warning') 4 | 5 | # import all into current namespace 6 | from helpers import * 7 | display('Not a warning') 8 | 9 | # import specific items into current namespace 10 | from helpers import display 11 | display('Not a warning') -------------------------------------------------------------------------------- /17 - JSON/create_json_from_dict.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | # Create a dictionary object 4 | person_dict = {'first': 'Christopher', 'last':'Harrison'} 5 | # Add additional key pairs to dictionary as needed 6 | person_dict['City']='Seattle' 7 | 8 | # Convert dictionary to JSON object 9 | person_json = json.dumps(person_dict) 10 | 11 | # Print JSON object 12 | print(person_json) 13 | -------------------------------------------------------------------------------- /4 - String variables/code_challenge.py: -------------------------------------------------------------------------------- 1 | # ask a user to enter their first name and store it in a variable 2 | # ask a user to enter their last name and store it in a variable 3 | # print their full name 4 | # Make sure you have a space between first and last name 5 | # Make sure the first letter of first name and last name is uppercase 6 | # Make sure the rest of the name is lowercase 7 | -------------------------------------------------------------------------------- /8 - Handling conditions/case_insensitive_comparisons.py: -------------------------------------------------------------------------------- 1 | country = 'CANADA' 2 | # by converting the string entered to lowercase and comparing it to a string 3 | # that is all lowercase letters I make the comparison case-insensitive 4 | # If someone types in CANADA or Canada it will still be a match 5 | if country.lower() == 'canada': 6 | print('Hello eh') 7 | else: 8 | print('Hello') 9 | -------------------------------------------------------------------------------- /13 - Functions/print_time_repeated_code.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | # print timestamps after each section of code 3 | # to see how long sections of code take to run 4 | 5 | first_name = 'Susan' 6 | print('task completed') 7 | print(datetime.datetime.now()) 8 | print() 9 | 10 | for x in range(0,10): 11 | print(x) 12 | print('task completed') 13 | print(datetime.datetime.now()) 14 | print() -------------------------------------------------------------------------------- /10 - Complex conditon checks/using_and.py: -------------------------------------------------------------------------------- 1 | # A student makes honour roll if their average is >=85 2 | # and their lowest grade is not below 70 3 | gpa = float(input('What was your Grade Point Average? ')) 4 | lowest_grade = input('What was your lowest grade? ') 5 | lowest_grade = float(lowest_grade) 6 | 7 | if gpa >= .85 and lowest_grade >= .70: 8 | print('You made the honour roll') 9 | 10 | -------------------------------------------------------------------------------- /13 - Functions/print_time_function_different_messages.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | # What if we want different messages displayed? 4 | # Can we still use a function? 5 | first_name = 'Susan' 6 | print('first name assigned') 7 | print(datetime.now()) 8 | print() 9 | 10 | for x in range(0,10): 11 | print(x) 12 | print('loop completed') 13 | print(datetime.now()) 14 | print() 15 | -------------------------------------------------------------------------------- /4 - String variables/format_strings.py: -------------------------------------------------------------------------------- 1 | # Ask the user for their first and last name 2 | first_name = input('What is your first name? ') 3 | last_name = input('What is your last name? ') 4 | 5 | # the capitalize function will return the string with 6 | # the first letter uppercase and the rest of the word lowercase 7 | print ('Hello ' + first_name.capitalize() + ' ' \ 8 | + last_name.capitalize()) 9 | -------------------------------------------------------------------------------- /6 - Dates/get_current_date.py: -------------------------------------------------------------------------------- 1 | #To get current date and time we need to use the datetime library 2 | from datetime import datetime 3 | 4 | current_date = datetime.now() 5 | # The now function returns current date and time as a datetime object 6 | 7 | # You must convert the datetime object to a string 8 | # before you can concatenate it to another string 9 | print('Today is: ' + str(current_date)) 10 | -------------------------------------------------------------------------------- /9 - Handling multiple conditions/nested_if.py: -------------------------------------------------------------------------------- 1 | country = input("What country do you live in? ") 2 | 3 | if country.lower() == 'canada': 4 | province = input("What province/state do you live in? ") 5 | if province in('Alberta',\ 6 | 'Nunavut','Yukon'): 7 | tax = 0.05 8 | elif province == 'Ontario': 9 | tax = 0.13 10 | else: 11 | tax = 0.15 12 | else: 13 | tax = 0.0 14 | print(tax) 15 | -------------------------------------------------------------------------------- /8 - Handling conditions/check_tax.py: -------------------------------------------------------------------------------- 1 | #Calculate the tax 2 | # Anything purchased for more than $1.00 is charged a 7% tax 3 | price = input('how much did you pay? ') 4 | 5 | # Convert the string to a number 6 | price = float(price) 7 | 8 | # Check if the price is greater than 1.00 9 | if price >= 1.00: 10 | # Everything over $1.00 is charged 7% tax 11 | tax = .07 12 | print('Tax rate is: ' + str(tax)) 13 | -------------------------------------------------------------------------------- /9 - Handling multiple conditions/use_in_statements.py: -------------------------------------------------------------------------------- 1 | province = input("What province do you live in? ") 2 | tax = 0 3 | # If multiple values cause the same output you can combine them by listing all 4 | # values you want to check for with the in operator 5 | if province in('Alberta','Nunavut','Yukon'): 6 | tax = 0.05 7 | elif province == 'Ontario': 8 | tax = 0.13 9 | else: 10 | tax = 0.15 11 | print(tax) -------------------------------------------------------------------------------- /2 - Print/print_blank_line.py: -------------------------------------------------------------------------------- 1 | # Each print statements starts on a new line 2 | print('Hello world') 3 | 4 | # If you pass nothing to the print statement you get a blank line 5 | print() 6 | print('Did you see that blank line?') 7 | 8 | # '\n' is a special character sequence that means print new line 9 | # you can use it to break the output over multiple lines 10 | print('Blank line \nin the middle of string') 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /2 - Print/coding_challenge.py: -------------------------------------------------------------------------------- 1 | # Here's a challenge for you to help you practice 2 | # See if you can fix the code below 3 | 4 | # print the message 5 | print('Why won't this line of code print') 6 | 7 | # print the message 8 | prnit('This line fails too!') 9 | 10 | # print the message 11 | print "I think I know how to fix this one" 12 | 13 | # print the name entered by the user 14 | input('Please tell me your name: ') 15 | print(name) 16 | -------------------------------------------------------------------------------- /13 - Functions/get_initials.py: -------------------------------------------------------------------------------- 1 | # Ask for a name and return the initials 2 | first_name = input('Enter your first name: ') 3 | first_name_initial = first_name[0:1] 4 | 5 | middle_name = input('Enter your middle name: ') 6 | middle_name_initial = middle_name[0:1] 7 | 8 | last_name = input('Enter your last name: ') 9 | last_name_initial = last_name[0:1] 10 | 11 | print('Your initials are: ' + first_name_initial \ 12 | + middle_name_initial + last_name_initial) 13 | 14 | -------------------------------------------------------------------------------- /7 - Error handling/README.md: -------------------------------------------------------------------------------- 1 | # Error handling 2 | 3 | Error handling in Python is managed through the use of [try/except/finally](https://docs.python.org/3.7/reference/compound_stmts.html#except) 4 | 5 | Python has numerous [built-in exceptions](https://docs.python.org/3.7/library/exceptions.html). When creating `except` blocks, they need to be created from most specific to most generic according to the [hierarchy](https://docs.python.org/3.7/library/exceptions.html#exception-hierarchy). 6 | -------------------------------------------------------------------------------- /5 - Numeric variables/numbers_treated_as_strings.py: -------------------------------------------------------------------------------- 1 | # Python has to guess what datatype a variable should be 2 | 3 | # since the input function returns a string, the variables it populates 4 | # will hold string values 5 | first_num = input('Enter first number ') 6 | second_num = input('Enter second number ') 7 | 8 | # Because first_num and second_num are string variables the + operator 9 | # concatenates them just like concatenating first_name and last_name 10 | print(first_num + second_num) -------------------------------------------------------------------------------- /8 - Handling conditions/code_challenge.py: -------------------------------------------------------------------------------- 1 | # Fix the mistakes in this code and test based on the description below 2 | # If I enter 2.00 I should see the message "Tax rate is: 0.07" 3 | # If I enter 1.00 I should see the message "Tax rate is: 0.07" 4 | # If I enter 0.50 I should see the message "Tax rate is: 0" 5 | price = input('how much did you pay? ') 6 | 7 | if price > 1.00: 8 | tax = .07 9 | print('Tax rate is: ' + str(tax)) 10 | else 11 | tax = 0 12 | print('Tax rate is: ' + str(tax)) -------------------------------------------------------------------------------- /8 - Handling conditions/add_else.py: -------------------------------------------------------------------------------- 1 | price = input('how much did you pay? ') 2 | price = float(price) 3 | 4 | if price >= 1.00: 5 | # Anything that costs $1.00 or more is charged 7% tax 6 | # All statements indented are only executed if price is > = 1 7 | tax = .07 8 | print('Tax rate is: ' + str(tax)) 9 | else: 10 | # Anything else we do not charge any tax 11 | # All statements indented are only executed if price is NOT >= 1 12 | tax = 0 13 | print('Tax rate is: ' + str(tax)) 14 | 15 | 16 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /18 - Decorators/creating_decorators.py: -------------------------------------------------------------------------------- 1 | import functools 2 | from colorama import init, Fore 3 | init() 4 | 5 | def color(color): 6 | def wrapper(func): 7 | @functools.wraps(func) 8 | def runner(*args, **kwargs): 9 | print(color + 'changing to blue') 10 | func(*args, **kwargs) 11 | return runner 12 | return wrapper 13 | 14 | @color(color=Fore.BLUE) 15 | def greeter(): 16 | print('Hello, world!!') 17 | print('Just saying hi again') 18 | 19 | greeter() -------------------------------------------------------------------------------- /13 - Functions/README.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | 3 | Functions allow you to take code that is repeated and move it to a module that can be called when needed. Functions are defined with the `def` keyword and must be declared before the function is called in your code. Functions can accept parameters and return values. 4 | 5 | - [Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions) 6 | 7 | ```python 8 | def functionname(parameter): 9 | # code to execute 10 | return value 11 | ``` 12 | -------------------------------------------------------------------------------- /13 - Functions/print_time_function.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | # Create a function called print_time 3 | # This function will print the message and current time 4 | def print_time(): 5 | print('task completed') 6 | print(datetime.datetime.now()) 7 | print() 8 | 9 | first_name = 'Susan' 10 | # Call print_time() function to display message and current time 11 | print_time() 12 | 13 | for x in range(0,10): 14 | print(x) 15 | # Call print_time() function to display message and current time 16 | print_time() -------------------------------------------------------------------------------- /3 - Comments/enable_pin.py: -------------------------------------------------------------------------------- 1 | #The enable_pin method is not coded yet 2 | # I have created a dummy method so the code 3 | # will run without an error 4 | # Don't panic if you don't understand this part of the code 5 | # we cover methods in a separate module 6 | def enable_pin(user, pin): 7 | print('pin enabled') 8 | 9 | # Set current_user and pin to test values 10 | current_user = 'TEST123' 11 | pin = '123456' 12 | 13 | # Enable PIN check as listed in 14 | # security requirements 15 | enable_pin(current_user, pin) 16 | 17 | -------------------------------------------------------------------------------- /8 - Handling conditions/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # Fix the mistakes in this code and test using the following 2 | # If I enter 2.00 I should see the message "Tax rate is: 0.07" 3 | # If I enter 1.00 I should see the message "Tax rate is: 0.07" 4 | # If I enter 0.50 I should see the message "Tax rate is: 0" 5 | price = input('how much did you pay? ') 6 | price = float(price) 7 | 8 | if price >= 1.00: 9 | tax = .07 10 | print('Tax rate is: ' + str(tax)) 11 | else: 12 | tax = 0 13 | print('Tax rate is: ' + str(tax)) -------------------------------------------------------------------------------- /17 - JSON/create_json_with_nested_dict.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | # Create a dictionary object 4 | person_dict = {'first': 'Christopher', 'last':'Harrison'} 5 | # Add additional key pairs to dictionary as needed 6 | person_dict['City']='Seattle' 7 | 8 | # create a staff dictionary 9 | # assign a person to a staff position of program manager 10 | staff_dict ={} 11 | staff_dict['Program Manager']=person_dict 12 | # Convert dictionary to JSON object 13 | staff_json = json.dumps(staff_dict) 14 | 15 | # Print JSON object 16 | print(staff_json) -------------------------------------------------------------------------------- /5 - Numeric variables/convert_strings_to_numbers_for_math.py: -------------------------------------------------------------------------------- 1 | first_num = input('Enter first number ') 2 | second_num = input('Enter second number ') 3 | # If you have a string variable containing a number 4 | # And you want to treat it as a number 5 | # You must convert it to a numeric datatype 6 | # int() converts a string to an integer e.g. 5, 8, 416, 506 7 | print(int(first_num) + int(second_num)) 8 | 9 | # float() converts a string to a decimal or float number e.g. 3.14159, 89.5, 1.0 10 | print(float(first_num) + float(second_num)) 11 | 12 | -------------------------------------------------------------------------------- /5 - Numeric variables/doing_math.py: -------------------------------------------------------------------------------- 1 | # Because the variables are assigned numeric values when created 2 | # Python knows they are numeric variables 3 | first_num = 6 4 | second_num = 2 5 | 6 | # You can peform a variety of math operations on numeric values 7 | print('addition') 8 | print(first_num + second_num) 9 | print('subtraction') 10 | print(first_num - second_num) 11 | print('multiplication') 12 | print(first_num * second_num) 13 | print('division') 14 | print(first_num / second_num) 15 | print ('exponent') 16 | print(first_num ** second_num) 17 | -------------------------------------------------------------------------------- /4 - String variables/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # ask a user to enter their first name and store it in a variable 2 | first_name = input('What is your first name? ') 3 | # ask a user to enter their last name and store it in a variable 4 | last_name = input('What is your last name? ') 5 | 6 | # print their full name 7 | # Make sure you have a space between first and last name 8 | # Make sure the first letter of first name and last name is uppercase 9 | # Make sure the rest of the name is lowercase 10 | print(first_name.capitalize() + ' ' + last_name.capitalize()) -------------------------------------------------------------------------------- /6 - Dates/date_functions.py: -------------------------------------------------------------------------------- 1 | #To get current date and time we need to use the datetime library 2 | from datetime import datetime, timedelta 3 | # The now function returns current date and time 4 | today = datetime.now() 5 | 6 | print('Today is: ' + str(today)) 7 | #You can use timedelta to add or remove days, or weeks to a date 8 | one_day = timedelta(days=1) 9 | yesterday = today - one_day 10 | print('Yesterday was: ' + str(yesterday)) 11 | 12 | one_week = timedelta(weeks=1) 13 | last_week = today - one_week 14 | print('Last week was: ' + str(last_week)) 15 | 16 | -------------------------------------------------------------------------------- /5 - Numeric variables/combining_strings_and_numbers.py: -------------------------------------------------------------------------------- 1 | days_in_feb = 28 2 | 3 | # The print function can accept numbers or strings 4 | print(days_in_feb) 5 | 6 | # The + operator can either add two numbers or it can concatenate two strings 7 | # it does not know what to do when you pass it one number and one string 8 | # This line of code will cause an error 9 | print(days_in_feb + ' days in February') 10 | 11 | # You need to convert the number to a string to display the value 12 | # This line of code will work 13 | print(str(days_in_feb) + ' days in February') 14 | 15 | -------------------------------------------------------------------------------- /18 - Decorators/README.md: -------------------------------------------------------------------------------- 1 | # Decorators 2 | 3 | [Decorators](https://www.python.org/dev/peps/pep-0318/) are similar to attributes in that they add meaning or functionality to blocks of code in Python. They're frequently used in frameworks such as [Flask](http://flask.pocoo.org/) or [Django](https://www.djangoproject.com/). The most common interaction you'll have with decorators as a Python developer is through using them rather than creating them. 4 | 5 | ``` python 6 | # Example decorator 7 | @log(True) 8 | def sample_function(): 9 | print('this is a sample function') 10 | ``` 11 | -------------------------------------------------------------------------------- /8 - Handling conditions/README.md: -------------------------------------------------------------------------------- 1 | # Handling conditions 2 | 3 | Conditional execution can be completed using the [if](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement) statement 4 | 5 | `if` syntax 6 | 7 | ```python 8 | if expression: 9 | # code to execute 10 | else: 11 | # code to execute 12 | ``` 13 | 14 | [Comparison operators](https://docs.python.org/3/library/stdtypes.html#comparisons) 15 | 16 | - < less than 17 | - < greater than 18 | - == is equal to 19 | - \>= greater than or equal to 20 | - <= less than or equal to 21 | - != not equal to 22 | -------------------------------------------------------------------------------- /17 - JSON/create_json_with_list.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | # Create a dictionary object 4 | person_dict = {'first': 'Christopher', 'last':'Harrison'} 5 | # Add additional key pairs to dictionary as needed 6 | person_dict['City']='Seattle' 7 | 8 | # Create a list object of programming languages 9 | languages_list = ['CSharp','Python','JavaScript'] 10 | 11 | # Add list object to dictionary for the languages key 12 | person_dict['languages']= languages_list 13 | 14 | # Convert dictionary to JSON object 15 | person_json = json.dumps(person_dict) 16 | 17 | # Print JSON object 18 | print(person_json) -------------------------------------------------------------------------------- /2 - Print/README.md: -------------------------------------------------------------------------------- 1 | # print 2 | 3 | The print function allows you to send output to the terminal 4 | 5 | - [print](https://docs.python.org/3/library/functions.html#print) 6 | 7 | Strings can be enclosed in single quotes or double quotes 8 | 9 | - "this is a string" 10 | - 'this is also a string' 11 | 12 | The input function allows you to prompt a user for a value 13 | 14 | - [input](https://docs.python.org/3/library/functions.html#input) 15 | 16 | Parameters: 17 | 18 | - `prompt`: Message to display to the user 19 | 20 | return value: 21 | 22 | - string value containing value entered by user 23 | -------------------------------------------------------------------------------- /13 - Functions/print_time_function_fix_import.py: -------------------------------------------------------------------------------- 1 | # Import datetime class from datetime library to simplify calls to datetime.now() 2 | from datetime import datetime 3 | 4 | # Create a function called print_time 5 | # This function will print the message and current time 6 | def print_time(): 7 | print('task completed') 8 | print(datetime.now()) 9 | print() 10 | 11 | first_name = 'Susan' 12 | # Call print_time() function to display message and current time 13 | print_time() 14 | 15 | for x in range(0,10): 16 | print(x) 17 | # Call print_time() function to display message and current time 18 | print_time() -------------------------------------------------------------------------------- /14 - Function parameters/get_initials_function.py: -------------------------------------------------------------------------------- 1 | # This function will take a name and return the 2 | # Create a function to return the first initial of a name 3 | # Parameters: 4 | # name: name of person 5 | # Return value 6 | # first letter of name passed in 7 | def get_initial(name): 8 | initial = name[0:1].upper() 9 | return initial 10 | 11 | # Ask for someone's name and return the initials 12 | first_name = input('Enter your first name: ') 13 | 14 | # Call get_initial function to retrieve first letter of name 15 | first_name_initial = get_initial(first_name) 16 | 17 | print('Your initial is: ' + first_name_initial) -------------------------------------------------------------------------------- /10 - Complex conditon checks/boolean_variables.py: -------------------------------------------------------------------------------- 1 | # I check to see if the requirements for honour roll are met 2 | gpa = float(input('What was your Grade Point Average? ')) 3 | lowest_grade = float(input('What was your lowest grade? ')) 4 | 5 | # Boolean variables allow you to remember a True/False value 6 | if gpa >= .85 and lowest_grade >= .70: 7 | honour_roll = True 8 | else: 9 | honour_roll = False 10 | 11 | # Somewhere later in your code if you need to check if students is 12 | # on honour roll, all I need to do is check the boolean variable 13 | # I set earlier in my code 14 | if honour_roll: 15 | print('You made honour roll') 16 | -------------------------------------------------------------------------------- /9 - Handling multiple conditions/code_challenge.py: -------------------------------------------------------------------------------- 1 | # Ask a user their name 2 | # If their first name starts with A or B 3 | # tell them they go to room AB 4 | # IF their first name starts with C 5 | # tell them to go to room CD 6 | # If their first name starts with another letter, ask for their last name 7 | # IF their last name starts with Z, tell them to go to room Z 8 | # if their last name starts with any other letter, tell them to go to room OTHER 9 | # When you are done 10 | # Anna should be in room AB 11 | # Bob should be in room AB 12 | # Charlie should be in room C 13 | # Khalid Haque should be in room OTHER 14 | # Xin Zhao should be in room Z -------------------------------------------------------------------------------- /5 - Numeric variables/README.md: -------------------------------------------------------------------------------- 1 | # Numeric values 2 | 3 | Python can store and manipulate numbers. Python has two types of numeric values: integers (whole numbers) or float (numbers with decimal places) 4 | 5 | - [numeric types](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) 6 | 7 | When naming variables follow the PEP-8 Style Guide for Python Code 8 | 9 | - [PEP-8 Style Guide](https://www.python.org/dev/peps/pep-0008/#naming-conventions) 10 | 11 | Converting to numeric values 12 | 13 | - [int](https://docs.python.org/3/library/functions.html#int) 14 | - [float](https://docs.python.org/3/library/functions.html#float) 15 | -------------------------------------------------------------------------------- /6 - Dates/format_date.py: -------------------------------------------------------------------------------- 1 | #To get current date and time we need to use the datetime library 2 | from datetime import datetime 3 | 4 | # The now function returns current date and time 5 | today = datetime.now() 6 | 7 | # use day, month, year, hour, minute, second functions 8 | # to display only part of the date 9 | # All these functions return integers 10 | # Convert them to strings before concatenating them to another string 11 | print('Day: ' + str(today.day)) 12 | print('Month: ' + str(today.month)) 13 | print('Year: ' + str(today.year)) 14 | 15 | print('Hour: ' + str(today.hour)) 16 | print('Minute: ' + str(today.minute)) 17 | print('Second: ' + str(today.second)) 18 | -------------------------------------------------------------------------------- /4 - String variables/README.md: -------------------------------------------------------------------------------- 1 | # Strings 2 | 3 | Python can store and manipulate strings. Strings can be enclosed in single or double quotes. There are a number of string methods you can use to manipulate and work with strings 4 | 5 | - [strings](https://docs.python.org/3/tutorial/introduction.html#strings) 6 | - [string methods](https://docs.python.org/3/library/stdtypes.html#string-methods) 7 | 8 | Converting to string values 9 | 10 | - [str](https://docs.python.org/3/library/functions.html#func-str) 11 | 12 | When naming variables follow the PEP-8 Style Guide for Python Code 13 | 14 | - [PEP-8 Style Guide](https://www.python.org/dev/peps/pep-0008/#naming-conventions) 15 | -------------------------------------------------------------------------------- /4 - String variables/string_functions.py: -------------------------------------------------------------------------------- 1 | # There are a number of string functions you can use 2 | # on string variables 3 | sentence = 'The dog is named Sammy' 4 | 5 | # upper will return the string in uppercase letters 6 | print(sentence.upper()) 7 | 8 | # lower will return the string in lowercase letters 9 | print(sentence.lower()) 10 | 11 | # capitalize will return the string with the first letter uppercase 12 | # and the rest of the string in lowercase 13 | print(sentence.capitalize()) 14 | 15 | # count will count the number of occurrences of the value specified 16 | # in the string, in this case how many times the letter 'a' appears 17 | print(sentence.count('a')) 18 | -------------------------------------------------------------------------------- /6 - Dates/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime, timedelta 2 | 3 | # print today's date 4 | current_date = datetime.now() 5 | print(current_date) 6 | 7 | # print yesterday's date 8 | one_day = timedelta(days=1) 9 | yesterday = current_date - one_day 10 | print('Yesterday was: ' + str(yesterday)) 11 | 12 | # ask a user to enter a date 13 | date_entered = input('Please enter a date (dd/mm/yyyy): ') 14 | date_entered = datetime.strptime(date_entered, '%d/%m/%Y') 15 | 16 | # print the date one week from the date entered 17 | one_week = timedelta(weeks=1) 18 | one_week_later = date_entered + one_week 19 | print('One week later it will be: ' + str(one_week_later)) -------------------------------------------------------------------------------- /17 - JSON/readme.md: -------------------------------------------------------------------------------- 1 | # JSON 2 | 3 | Many APIs return data in [JSON](https://json.org/), JavaScript Object Notation. JSON is a standard format that can is readable by humans and parsed or generated by code. 4 | 5 | JSON is built on two structures: 6 | - collections of key/value pairs 7 | - lists of values 8 | 9 | JSON Linters will format JSON so it easier to read by a human. The following website have JSON linters: 10 | - [JSONLint](https://jsonlint.com/) 11 | - [ConvertJson.com](http://www.convertjson.com/jsonlint.htm) 12 | - [JSON schema linter](https://www.json-schema-linter.com/) 13 | 14 | Python includes a [json](https://docs.python.org/2/library/json.html) module which helps you encode and decode JSON -------------------------------------------------------------------------------- /5 - Numeric variables/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # Ask a user to enter a number 2 | first_number = input('Enter a number: ') 3 | 4 | # Ask a user to enter a second number 5 | second_number = input('Enter another number: ') 6 | 7 | # Calculate the total of the two numbers added together 8 | answer = float(first_number) + float(second_number) 9 | 10 | # Print 'first number + second number = answer' 11 | # For example if someone enters 4 and 6 the output should read 12 | # 4 + 6 = 10 13 | print(first_number + ' + ' + second_number + ' = ' + str(answer)) 14 | 15 | # If you do not want the decimal places you could round the answer 16 | print(first_number + ' + ' + second_number + ' = ' + str(round(answer))) -------------------------------------------------------------------------------- /12 - Loops/README.md: -------------------------------------------------------------------------------- 1 | # Loops 2 | 3 | ## For loops 4 | 5 | [For loops](https://docs.python.org/3/reference/compound_stmts.html#the-for-statement) takes each item in an array or collection in order, and assigns it to the variable you define. 6 | 7 | ``` python 8 | names = ['Christopher', 'Susan'] 9 | for name in names: 10 | print(name) 11 | ``` 12 | 13 | ## While loops 14 | 15 | [While loops](https://docs.python.org/3/reference/compound_stmts.html#the-while-statement) perform an operation as long as a condition is true. 16 | 17 | ``` python 18 | names = ['Christopher', 'Susan'] 19 | index = 0 20 | while index < len(names): 21 | name = names[index] 22 | print(name) 23 | index = index + 1 24 | ``` 25 | -------------------------------------------------------------------------------- /13 - Functions/print_time_with_message_parameter.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | # Define a function to print the current time and task name 4 | # Function the following parameters: 5 | # task_name: Name of the task to display to output screen 6 | def print_time(task_name): 7 | print(task_name) 8 | print(datetime.now()) 9 | print() 10 | 11 | first_name = 'Susan' 12 | # Call print_time() function to display message and current time 13 | # pass in name of task completed 14 | print_time('first name assigned') 15 | 16 | for x in range(0,10): 17 | print(x) 18 | # Call print_time() function to display message and current time 19 | # pass in name of task completed 20 | print_time('loop completed') 21 | -------------------------------------------------------------------------------- /2 - Print/coding_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # Here's a challenge for you to help you practice 2 | # See if you can fix the code below 3 | 4 | # print the message 5 | # There was a single quote inside the string! 6 | # Use double quotes to enclose the string 7 | print("Why won't this line of code print") 8 | 9 | # print the message 10 | # There was a mistake in the function name 11 | print('This line fails too!') 12 | 13 | # print the message 14 | # Need to add the () around the string 15 | print ("I think I know how to fix this one") 16 | 17 | # print the name entered by the user 18 | # You need to store the value returned by the input statement 19 | # in a variable 20 | name = input('Please tell me your name: ') 21 | print(name) 22 | -------------------------------------------------------------------------------- /13 - Functions/code_challenge.py: -------------------------------------------------------------------------------- 1 | # Create a calculator function 2 | # The function should accept three parameters: 3 | # first_number: a numeric value for the math operation 4 | # second_number: a numeric value for the math operation 5 | # operation: the word 'add' or 'subtract' 6 | # the function should return the result of the two numbers added or subtracted 7 | # based on the value passed in for the operator 8 | # 9 | # Test your function with the values 6,4, add 10 | # Should return 10 11 | # 12 | # Test your function with the values 6,4, subtract 13 | # Should return 2 14 | # 15 | # BONUS: Test your function with the values 6, 4 and divide 16 | # Have your function return an error message when invalid values are received 17 | 18 | -------------------------------------------------------------------------------- /6 - Dates/README.md: -------------------------------------------------------------------------------- 1 | # Date values 2 | 3 | The [datetime module](https://docs.python.org/3/library/datetime.html) contains a number of classes for manipulating dates and times. 4 | 5 | Date and time types: 6 | 7 | - `date` stores year, month, and day 8 | - `time` stores hour, minute, and second 9 | - `datetime` stores year, month, day, hour, minute, and second 10 | - `timedelta` a duration of time between two dates, times, or datetimes 11 | 12 | When naming variables follow the PEP-8 Style Guide for Python Code 13 | 14 | - [PEP-8 Style Guide](https://www.python.org/dev/peps/pep-0008/#naming-conventions) 15 | 16 | Converting from string to datetime 17 | 18 | - [strptime](https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior) 19 | -------------------------------------------------------------------------------- /13 - Functions/getting_clever_with_functions_harder_to_read.py: -------------------------------------------------------------------------------- 1 | # Create function get_initial to accept a name and 2 | # return the first letter of the name in uppercase 3 | # Parameters: 4 | # name: the name of a person 5 | # Return value: 6 | # first letter of name passed in as a parameter in uppercase 7 | def get_initial(name): 8 | initial = name[0:1].upper() 9 | return initial 10 | 11 | #Ask for someone's name and return the initials 12 | first_name = input('Enter your first name: ') 13 | middle_name = input('Enter your middle name: ') 14 | last_name = input('Enter your last name: ') 15 | 16 | # Call get_initial function to return first letter of a name 17 | print('Your initials are: ' \ 18 | + get_initial(first_name) \ 19 | + get_initial(middle_name) \ 20 | + get_initial(last_name)) -------------------------------------------------------------------------------- /14 - Function parameters/get_initials_multiple_parameters.py: -------------------------------------------------------------------------------- 1 | # Create a function to return the first initial of a name 2 | # Parameters: 3 | # name: name of person 4 | # force_uppercase: indicates if you always want the initial to be in upppercase 5 | # Return value 6 | # first letter of name passed in 7 | def get_initial(name, force_uppercase): 8 | if force_uppercase: 9 | initial = name[0:1].upper() 10 | else: 11 | initial = name[0:1] 12 | return initial 13 | 14 | #Ask for someone's name and return the initial 15 | first_name = input('Enter your first name: ') 16 | 17 | # Call get_initial function to retrieve first letter of name 18 | # Alwasy return initial in uppercase 19 | first_name_initial = get_initial(first_name, False) 20 | 21 | print('Your initial is: ' + first_name_initial) -------------------------------------------------------------------------------- /14 - Function parameters/code_challenge.py: -------------------------------------------------------------------------------- 1 | # Create a calculator function 2 | # The function should accept three parameters: 3 | # first_number: a numeric value for the math operation 4 | # second_number: a numeric value for the math operation 5 | # operation: the word 'add' or 'subtract'. The default operation is 'add' 6 | # the function should return the result of the two numbers added or subtracted 7 | # based on the value passed in for the operator 8 | # 9 | # Test your function using named notation passing in only the numbers 6 and 4 10 | # Should return 10 11 | # 12 | # Test your function using named notation with the values 6,4, subtract 13 | # Should return 2 14 | # 15 | # BONUS: Test your function with the values 6, 4 and divide 16 | # Have your function return an error message when invalid values are received 17 | -------------------------------------------------------------------------------- /6 - Dates/input_date.py: -------------------------------------------------------------------------------- 1 | # import the datetime and timedelta modules 2 | from datetime import datetime, timedelta 3 | 4 | # When you ask a user for a date tell them the desired date format 5 | birthday = input('When is your birthday (dd/mm/yyyy)? ') 6 | 7 | # When you convert the string containing the date into a date object 8 | # you must specify the expected date format 9 | # if the date is not in the expected format Python will raise an exception 10 | birthday_date = datetime.strptime(birthday, '%d/%m/%Y') 11 | 12 | print ('Birthday: ' + str(birthday_date)) 13 | 14 | # Because we converted the string into a date object 15 | # We can use date and time functions such as timedelta with the object 16 | one_day = timedelta(days=1) 17 | birthday_eve = birthday_date - one_day 18 | print('Day before birthday: ' + str(birthday_eve)) 19 | -------------------------------------------------------------------------------- /14 - Function parameters/get_initials_default_values.py: -------------------------------------------------------------------------------- 1 | # Create a function to return the first initial of a name 2 | # Parameters: 3 | # name: name of person 4 | # force_uppercase: indicates if you always want the initial to be in upppercase: default is True 5 | # Return value 6 | # first letter of name passed in 7 | def get_initial(name, force_uppercase=True): 8 | if force_uppercase: 9 | initial = name[0:1].upper() 10 | else: 11 | initial = name[0:1] 12 | return initial 13 | 14 | # Ask for someone's name and return the initial 15 | first_name = input('Enter your first name: ') 16 | 17 | # Call get_initial function to retrieve first letter of name 18 | # not passing a value for force_uppercase so default value is used 19 | first_name_initial = get_initial(first_name) 20 | 21 | print('Your initial is: ' + first_name_initial) -------------------------------------------------------------------------------- /14 - Function parameters/get_initials_named_parameters.py: -------------------------------------------------------------------------------- 1 | # Create a function to return the first initial of a name 2 | # Parameters: 3 | # name: name of person 4 | # force_uppercase: indicates if you always want the initial to be in upppercase 5 | # Return value 6 | # first letter of name passed in 7 | def get_initial(name, force_uppercase): 8 | if force_uppercase: 9 | initial = name[0:1].upper() 10 | else: 11 | initial = name[0:1] 12 | return initial 13 | 14 | # Ask for someone's name and return the initial 15 | first_name = input('Enter your first name: ') 16 | 17 | # Call get_initial to retrieve first letter of name 18 | # When you use named notation, you can specify parameters in any order 19 | first_name_initial = get_initial(force_uppercase=True, \ 20 | name=first_name) 21 | 22 | print('Your initial is: ' + first_name_initial) -------------------------------------------------------------------------------- /9 - Handling multiple conditions/README.md: -------------------------------------------------------------------------------- 1 | # Handling conditions 2 | 3 | Conditional execution can be completed using the [if](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement) statement. Adding `elif` allows you to check multiple conditions 4 | 5 | `if` syntax 6 | 7 | ```python 8 | if expression: 9 | # code to execute 10 | elif expression: 11 | # code to execute 12 | else: 13 | # code to execute 14 | ``` 15 | 16 | [Boolean operators](https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not) 17 | 18 | - **x *or* y** - If either x OR y is true, the expression is executed 19 | 20 | [Comparison operators](https://docs.python.org/3/library/stdtypes.html#comparisons) 21 | 22 | - < less than 23 | - < greater than 24 | - == is equal to 25 | - \>= greater than or equal to 26 | - <= less than or equal to 27 | - != not equal to 28 | - **x *in* [a,b,c]** Does x match the value of a, b, or c 29 | -------------------------------------------------------------------------------- /13 - Functions/get_initails_function.py: -------------------------------------------------------------------------------- 1 | # Create function get_initial to accept a name and 2 | # return the first letter of the name in uppercase 3 | # Parameters: 4 | # name: the name of a person 5 | # Return value: 6 | # first letter of name passed in as a parameter in uppercase 7 | def get_initial(name): 8 | initial = name[0:1].upper() 9 | return initial 10 | 11 | # This program will ask for someone's name and return the initials 12 | first_name = input('Enter your first name: ') 13 | # Call get_initial to retrieve initial of name 14 | first_name_initial = get_initial(first_name) 15 | 16 | middle_name = input('Enter your middle name: ') 17 | # Call get_initial to retrieve initial of name 18 | middle_name_initial = get_initial(middle_name) 19 | 20 | last_name = input('Enter your last name: ') 21 | # Call get_initial to retrieve initial of name 22 | last_name_initial = get_initial(last_name) 23 | 24 | print('Your initials are: ' + first_name_initial \ 25 | + middle_name_initial + last_name_initial) -------------------------------------------------------------------------------- /11 - Collections/README.md: -------------------------------------------------------------------------------- 1 | # Collections 2 | 3 | Collections are groups of items. Python supports several types of collections. Three of the most common are dictionaries, lists and arrays. 4 | 5 | ## Lists 6 | 7 | [Lists](https://docs.python.org/3/tutorial/introduction.html#lists) are a collection of items. Lists can be expanded or contracted as needed, and can contain any data type. Lists are most commonly used to store a single column collection of information, however it is possible to [nest lists](https://docs.python.org/3/tutorial/datastructures.html#nested-list-comprehensions) 8 | ## Arrays 9 | 10 | [Arrays](https://docs.python.org/3/library/array.html) are similar to lists, however are designed to store a uniform basic data type, such as integers or floating point numbers. 11 | 12 | ## Dictionaries 13 | 14 | [Dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) are key/value pairs of a collection of items. Unlike a list where items can only be accessed by their index or value, dictionaries use keys to identify each item. 15 | -------------------------------------------------------------------------------- /10 - Complex conditon checks/readme.md: -------------------------------------------------------------------------------- 1 | # Complex condition checks 2 | 3 | Conditional execution can be completed using the [if](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement) statement. 4 | 5 | `if` syntax 6 | 7 | ```python 8 | if expression: 9 | # code to execute 10 | elif expression: 11 | # code to execute 12 | else: 13 | # code to execute 14 | ``` 15 | 16 | [Boolean values](https://docs.python.org/3/library/stdtypes.html#boolean-values) can be either `False` or `True` 17 | 18 | [Boolean operators](https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not) 19 | 20 | - **x *or* y** - If either x **OR** y is true, the expression is executed 21 | - **x *and* y** - If x **AND** y are both true, the expression is executed 22 | 23 | [Comparison operators](https://docs.python.org/3/library/stdtypes.html#comparisons) 24 | 25 | - < less than 26 | - < greater than 27 | - == is equal to 28 | - \>= greater than or equal to 29 | - <= less than or equal to 30 | - != not equal to 31 | - **x *in* [a,b,c]** Does x match the value of a, b, or c 32 | -------------------------------------------------------------------------------- /10 - Complex conditon checks/code_challenge.py: -------------------------------------------------------------------------------- 1 | # When you join a hockey team you get your name on the back of the jersey 2 | # but the jersey may not be big enough to hold all the letters 3 | # Ask the user for their first name 4 | 5 | # Ask the user for their last name 6 | 7 | # if first name is < 10 characters and last name is < 10 characters 8 | # print first and last name on the jersey 9 | # if first name >= 10 characters long and last name is < 10 characters 10 | # print first initial of first name and the entire last name 11 | # if first name < 10 characters long and last name is >= 10 characters 12 | # print entire first name and first initial of last name 13 | # if first name >= 10 characters long and last name is >= 10 characters 14 | # print last name only 15 | 16 | # Test with the following values 17 | # first name: Susan last name: Ibach 18 | # output: Susan Ibach 19 | # first name: Susan last name: ReallyLongLastName 20 | # output: Susan R. 21 | # first name: ReallyLongFirstName last name: Ibach 22 | # output: R. Ibach 23 | # first name: ReallyLongFirstName last name: ReallyLongLastName 24 | # output: ReallyLongLastName -------------------------------------------------------------------------------- /9 - Handling multiple conditions/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # Assign people to different rooms when they check in based on their names 2 | # When you are done 3 | # Anna should be in room AB 4 | # Bob should be in room AB 5 | # Charlie should be in room C 6 | # Khalid Haque should be in room OTHER 7 | # Xin Zhao should be in room Z 8 | # Ask a user their first name 9 | name = input('What is your name? ') 10 | 11 | # If their first name starts with A or B 12 | # tell them they go to room AB 13 | first_letter = name[0:1] 14 | if first_letter.upper() in ('A','B'): 15 | room = 'AB' 16 | # If their first name starts with C 17 | # tell them to go to room C 18 | elif first_letter.upper() == 'C': 19 | room = 'C' 20 | else: 21 | # If their first name starts with another letter, ask for their last name 22 | # If their last name starts with Z, tell them to go to room Z 23 | last_name = input('what is your last name? ') 24 | last_name_first_letter = last_name[0:1] 25 | # if their last name starts with any other letter, tell them to go to room OTHER 26 | if last_name_first_letter == 'Z': 27 | room = 'Z' 28 | else: 29 | room = 'OTHER' 30 | print('Please go to room ' + room) 31 | 32 | -------------------------------------------------------------------------------- /13 - Functions/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # Create a calculator function 2 | # The function should accept three parameters: 3 | # first_number: a numeric value for the math operation 4 | # second_number: a numeric value for the math operation 5 | # operation: the word 'add' or 'subtract' 6 | # the function should return the result of the two numbers added or subtracted 7 | # based on the value passed in for the operator 8 | # 9 | 10 | def calculator(first_number, second_number, operation): 11 | if operation.upper() == 'ADD': 12 | return(float(first_number) + float(second_number)) 13 | elif operation.upper() =='SUBTRACT': 14 | return(float(first_number) - float(second_number)) 15 | else: 16 | return('Invalid operation please specify ADD or SUBTRACT') 17 | # Test your function with the values 6,4, add 18 | # Should return 10 19 | # 20 | print('Adding 6 + 4 = ' + str(calculator(6,4,'add'))) 21 | # Test your function with the values 6,4, subtract 22 | # Should return 2 23 | print('Subtracting 6 - 4 = ' + str(calculator(6,4,'subtract'))) 24 | # Test your function with the values 6,4, divide 25 | # Should return some sort of error message 26 | print('Dividing 6 / 4 = ' + str(calculator(6,4,'divide'))) -------------------------------------------------------------------------------- /14 - Function parameters/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # Create a calculator function 2 | # The function should accept three parameters: 3 | # first_number: a numeric value for the math operation 4 | # second_number: a numeric value for the math operation 5 | # operation: the word 'add' or 'subtract'. The default operation is 'add' 6 | # the function should return the result of the two numbers added or subtracted 7 | # based on the value passed in for the operator 8 | # 9 | def calculator(first_number, second_number, operation='ADD'): 10 | if operation.upper() == 'ADD': 11 | return(float(first_number) + float(second_number)) 12 | elif operation.upper() =='SUBTRACT': 13 | return(float(first_number) - float(second_number)) 14 | else: 15 | return('Invalid operation please specify ADD or SUBTRACT') 16 | 17 | 18 | # Test your function using named notation passing in only the numbers 6 and 4 19 | # Should return 10 20 | 21 | print('Adding 6 + 4 = ' + str(calculator(first_number=6, second_number=4))) 22 | # Test your function using named notation with the values 6,4, subtract 23 | # Should return 2 24 | # 25 | print('Subtracting 6 - 4 = ' + str(calculator(first_number=6, second_number=4, operation='subtract'))) 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /15 - Packages/README.md: -------------------------------------------------------------------------------- 1 | # Packages and modules 2 | 3 | ## Modules 4 | 5 | [Modules](https://docs.python.org/3/tutorial/modules.html) allow you to store reusable blocks of code, such as functions, in separate files. They're referenced by using the `import` statement. 6 | 7 | ``` python 8 | # import module as namespace 9 | import helpers 10 | helpers.display('Not a warning') 11 | 12 | # import all into current namespace 13 | from helpers import * 14 | display('Not a warning') 15 | 16 | # import specific items into current namespace 17 | from helpers import display 18 | display('Not a warning') 19 | ``` 20 | 21 | ## Packages 22 | 23 | [Distribution packages](https://packaging.python.org/glossary/#term-distribution-package) are external archive files which contain resources such as classes and functions. Most every application you create will make use of one or more packages. Imports from packages follow the same syntax as modules you've created. The [Python Package index](https://pypi.org/) contains a full list of packages you can install using [pip](https://pip.pypa.io/en/stable/). 24 | 25 | ## Virtual environments 26 | 27 | [Virtual environments](https://docs.python.org/3.7/library/exceptions.html) allow you to install packages into an isolated folder. This allows you to better manage versions. 28 | 29 | ``` console 30 | 31 | ``` 32 | -------------------------------------------------------------------------------- /16 - Calling APIs/readme.md: -------------------------------------------------------------------------------- 1 | # Calling APIs 2 | 3 | You can call functions called by other programs hosted on web servers. 4 | [Microsoft Azure Cognitive Services](https://docs.microsoft.com/en-ca/azure/cognitive-services/) contain a number of APIs you can call from your code to add intelligence to your apps and websites. 5 | 6 | In the code example you call the [Analyze Image](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa0) function of the [Computer Vision](https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/) 7 | 8 | Calling the API requires 9 | - [API Key](https://azure.microsoft.com/en-ca/try/cognitive-services/) to give you permission to call the API 10 | - Address or Endpoint of the service 11 | - function name of method to call as listed in the [API documentation](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa) 12 | - function parameters as listed in the [API documentation](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa) 13 | - HTTP Headers as listed in the [API documentation](https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa) 14 | 15 | -------------------------------------------------------------------------------- /16 - Calling APIs/code_challenge.py: -------------------------------------------------------------------------------- 1 | # Challenge #1 2 | # Create an Azure Custom Vision Service 3 | # Analyze an image and return the JSON describing the image. 4 | # call_api.py is a completed solution, but it will not run unless 5 | # you do the following: 6 | # Create a Custom Vision Service in Azure 7 | # Update the Key 8 | # Update the address of your service 9 | # Update the image file and location 10 | 11 | # Bonus Challenge 12 | # Your skills are growing, it's time to start trying to figure things out on your own 13 | # based on documentation. You have already called one function of the Computer Vision Service 14 | # Now try calling another 15 | # Instead of calling the analyze method of the service, try calling the OCR method 16 | # Here is some helpful documentation 17 | # https://docs.microsoft.com/en-us/azure/cognitive-services/Computer-vision/concept-recognizing-text#ocr-optical-character-recognition-api 18 | # https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fc 19 | # Use the documentation to figure out 20 | # The correct function name for the address 21 | # The parameters you need to pass the function 22 | # The HTTP Headers required 23 | # Pass in an image containing text 24 | # The JSON returned will contain the string of text in the image 25 | # Good luck! 26 | -------------------------------------------------------------------------------- /14 - Function parameters/readme.md: -------------------------------------------------------------------------------- 1 | # Function parameters 2 | 3 | Functions allow you to take code that is repeated and move it to a module that can be called when needed. Functions are defined with the `def` keyword and must be declared before the function is called in your code. Functions can accept one or more parameters and return values. 4 | 5 | - [Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions) 6 | 7 | ```python 8 | def function_name(parameter): 9 | # code to execute 10 | return value 11 | ``` 12 | 13 | Parameters can be assigned a [default value](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values) making them optional when the function is called. 14 | 15 | ```python 16 | def function_name(parameter=default): 17 | # code to execute 18 | return value 19 | ``` 20 | 21 | When you call a function you may specify the values for the parameters using positional or [named notation](https://docs.python.org/3/tutorial/controlflow.html#keyword-arguments) 22 | 23 | ```python 24 | def function_name(parameter1, parameter2): 25 | # code to execute 26 | return value 27 | 28 | # Positional notation pass in arguments in same order as parameters are declared 29 | result = function_name(value1,value2) 30 | 31 | # Named notation 32 | result = function_name(parameter1=value1, parameter2=value2) 33 | ``` 34 | -------------------------------------------------------------------------------- /10 - Complex conditon checks/code_challenge_solution.py: -------------------------------------------------------------------------------- 1 | # When you join a hockey team you get your name on the back of the jersey 2 | # but the jersey may not be big enough to hold all the letters 3 | # Ask the user for their first name 4 | first_name = input('Please enter your first name: ') 5 | # Ask the user for their last name 6 | last_name = input('Please enter your last name: ') 7 | 8 | # if first name is < 10 characters and last name is < 10 characters 9 | # print first and last name on the jersey 10 | # if first name >= 10 characters long and last name is < 10 characters 11 | # print first initial of first name and the entire last name 12 | # if first name < 10 characters long and last name is >= 10 characters 13 | # print entire first name and first initial of last name 14 | # if first name >= 10 characters long and last name is >= 10 characters 15 | # print last name only 16 | 17 | # Check length of first name 18 | if len(first_name) >=10: 19 | long_first_name = True 20 | else: 21 | long_first_name = False 22 | 23 | # Check length of last name 24 | if len(last_name) >= 10: 25 | long_last_name = True 26 | else: 27 | long_last_name = False 28 | 29 | # Evaluate possible jersey print combinations for different lengths 30 | if long_first_name and long_last_name: 31 | print(last_name) 32 | elif long_first_name: 33 | print(first_name[0:1] + '. ' + last_name) 34 | elif long_last_name: 35 | print(first_name + ' ' + last_name[0:1] + '.') 36 | else: 37 | print(first_name + ' ' + last_name) -------------------------------------------------------------------------------- /14 - Function parameters/named_parameters_make_code_readable.py: -------------------------------------------------------------------------------- 1 | # Create a function to handle errors that occur during code execution 2 | # This will display a message to the user adn may log the error for the support team to 3 | # help with debugging 4 | # 5 | # Parameters: 6 | # error_code: Unique error code assigned to each type of error: e.g. 45 is datatype conversion error 7 | # error_severity: 0 - fatal error should never occur 8 | # 1 - severe error code cannot continue 9 | # 2 - warning code can continue but may be missing information in records 10 | # log_to_db: Should this error be logged to the database 11 | # error_message: Error message to display to user and write to database 12 | # source_module: Name of the python module that generated ther error 13 | 14 | def error_logger(error_code, error_severity, log_to_db, error_message, source_module): 15 | print('oh no error: ' + error_message) 16 | # Imagine code here that logs our error to a database or file 17 | 18 | first_number = 10 19 | second_number = 5 20 | # This function call by itself is confusing, I have to look at the 21 | # definition of the error_logger function to understand it 22 | if first_number > second_number: 23 | error_logger(45,1,True,'Second number greater than first','adding_method') 24 | 25 | 26 | if first_number > second_number: 27 | # This function call by itself is easier to understand because I can 28 | # see how the values I pass in map to the function parameters 29 | error_logger(error_code=45, 30 | error_severity=1, 31 | log_to_db=True, 32 | error_message='Second number greater than first', 33 | source_module='adding_method') 34 | -------------------------------------------------------------------------------- /16 - Calling APIs/call_api.py: -------------------------------------------------------------------------------- 1 | # This code will show you how to call the Computer Vision API from Python 2 | # You can find documentation on the Computer Vision Analyze Image method here 3 | # https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa 4 | 5 | # Use the requests library to simplify making a REST API call from Python 6 | import requests 7 | 8 | # We will need the json library to read the data passed back 9 | # by the web service 10 | import json 11 | 12 | # You need to update the SUBSCRIPTION_KEY to 13 | # they key for your Computer Vision Service 14 | SUBSCRIPTION_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxx" 15 | 16 | # You need to update the vision_service_address to the address of 17 | # your Computer Vision Service 18 | vision_service_address = "https://canadacentral.api.cognitive.microsoft.com/vision/v2.0/" 19 | 20 | # Add the name of the function you want to call to the address 21 | address = vision_service_address + "analyze" 22 | 23 | # According to the documentation for the analyze image function 24 | # There are three optional parameters: language, details & visualFeatures 25 | parameters = {'visualFeatures':'Description,Color', 26 | 'language':'en'} 27 | 28 | # Open the image file to get a file object containing the image to analyze 29 | image_path = "./TestImages/PolarBear.jpg" 30 | image_data = open(image_path, "rb").read() 31 | 32 | # According to the documentation for the analyze image function 33 | # we need to specify the subscription key and the content type 34 | # in the HTTP header. Content-Type is application/octet-stream when you pass in a image directly 35 | headers = {'Content-Type': 'application/octet-stream', 36 | 'Ocp-Apim-Subscription-Key': SUBSCRIPTION_KEY} 37 | 38 | # According to the documentation for the analyze image function 39 | # we use HTTP POST to call this function 40 | response = requests.post(address, headers=headers, params=parameters, data=image_data) 41 | 42 | # Raise an exception if the call returns an error code 43 | response.raise_for_status() 44 | 45 | # Display the JSON results returned 46 | results = response.json() 47 | print(json.dumps(results)) 48 | -------------------------------------------------------------------------------- /17 - JSON/read_key_pair.py: -------------------------------------------------------------------------------- 1 | # This code will show you how to call the Computer Vision API from Python 2 | # You can find documentation on the Computer Vision Analyze Image method here 3 | # https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa 4 | 5 | # Use the requests library to simplify making a REST API call from Python 6 | import requests 7 | 8 | # We will need the json library to read the data passed back 9 | # by the web service 10 | import json 11 | 12 | # We need the address of our Computer vision service 13 | vision_service_address = "https://canadacentral.api.cognitive.microsoft.com/vision/v2.0/" 14 | # Add the name of the function we want to call to the address 15 | address = vision_service_address + "analyze" 16 | 17 | # According to the documentation for the analyze image function 18 | # There are three optional parameters: language, details & visualFeatures 19 | parameters = {'visualFeatures':'Description,Color', 20 | 'language':'en'} 21 | 22 | # We need the key to access our Computer Vision Service 23 | subscription_key = "xxxxxxxxxxxxxxxxxxxx" 24 | 25 | # Open the image file to get a file object containing the image to analyze 26 | image_path = "./TestImages/PolarBear.jpg" 27 | image_data = open(image_path, 'rb').read() 28 | 29 | # According to the documentation for the analyze image function 30 | # we need to specify the subscription key and the content type 31 | # in the HTTP header. Content-Type is application/octet-stream when you pass in a image directly 32 | headers = {'Content-Type': 'application/octet-stream', 33 | 'Ocp-Apim-Subscription-Key': subscription_key} 34 | 35 | # According to the documentation for the analyze image function 36 | # we use HTTP POST to call this function 37 | response = requests.post(address, headers=headers, params=parameters, data=image_data) 38 | 39 | # Raise an exception if the call returns an error code 40 | response.raise_for_status() 41 | 42 | # Display the raw JSON results returned 43 | results = response.json() 44 | print(json.dumps(results)) 45 | 46 | # print the value for requestId from the JSON output 47 | print() 48 | print('requestId') 49 | print (results['requestId']) -------------------------------------------------------------------------------- /17 - JSON/read_subkey.py: -------------------------------------------------------------------------------- 1 | # This code will show you how to call the Computer Vision API from Python 2 | # You can find documentation on the Computer Vision Analyze Image method here 3 | # https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa 4 | 5 | # Use the requests library to simplify making a REST API call from Python 6 | import requests 7 | 8 | # We will need the json library to read the data passed back 9 | # by the web service 10 | import json 11 | 12 | # We need the address of our Computer vision service 13 | vision_service_address = "https://canadacentral.api.cognitive.microsoft.com/vision/v2.0/" 14 | # Add the name of the function we want to call to the address 15 | address = vision_service_address + "analyze" 16 | 17 | # According to the documentation for the analyze image function 18 | # There are three optional parameters: language, details & visualFeatures 19 | parameters = {'visualFeatures':'Description,Color', 20 | 'language':'en'} 21 | 22 | # We need the key to access our Computer Vision Service 23 | subscription_key = "xxxxxxxxxxxxxxxxxxxxxxx" 24 | 25 | # Open the image file to get a file object containing the image to analyze 26 | image_path = "./TestImages/PolarBear.jpg" 27 | image_data = open(image_path, 'rb').read() 28 | 29 | # According to the documentation for the analyze image function 30 | # we need to specify the subscription key and the content type 31 | # in the HTTP header. Content-Type is application/octet-stream when you pass in a image directly 32 | headers = {'Content-Type': 'application/octet-stream', 33 | 'Ocp-Apim-Subscription-Key': subscription_key} 34 | 35 | # According to the documentation for the analyze image function 36 | # we use HTTP POST to call this function 37 | response = requests.post(address, headers=headers, params=parameters, data=image_data) 38 | 39 | # Raise an exception if the call returns an error code 40 | response.raise_for_status() 41 | 42 | # Display the raw JSON results returned 43 | results = response.json() 44 | print(json.dumps(results)) 45 | 46 | # Print the value for dominantColorBackground from the color keys 47 | print() 48 | print('dominantColorBackground') 49 | print(results['color']['dominantColorBackground']) -------------------------------------------------------------------------------- /17 - JSON/read_key_pair_list.py: -------------------------------------------------------------------------------- 1 | # This code will show you how to call the Computer Vision API from Python 2 | # You can find documentation on the Computer Vision Analyze Image method here 3 | # https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa 4 | 5 | # Use the requests library to simplify making a REST API call from Python 6 | import requests 7 | 8 | # We will need the json library to read the data passed back 9 | # by the web service 10 | import json 11 | 12 | # We need the address of our Computer vision service 13 | vision_service_address = "https://canadacentral.api.cognitive.microsoft.com/vision/v2.0/" 14 | # Add the name of the function we want to call to the address 15 | address = vision_service_address + "analyze" 16 | 17 | # According to the documentation for the analyze image function 18 | # There are three optional parameters: language, details & visualFeatures 19 | parameters = {'visualFeatures':'Description,Color', 20 | 'language':'en'} 21 | 22 | # We need the key to access our Computer Vision Service 23 | subscription_key = "xxxxxxxxxxxxxxxxxxxxxxx" 24 | 25 | # Open the image file to get a file object containing the image to analyze 26 | image_path = "./TestImages/PolarBear.jpg" 27 | image_data = open(image_path, 'rb').read() 28 | 29 | # According to the documentation for the analyze image function 30 | # we need to specify the subscription key and the content type 31 | # in the HTTP header. Content-Type is application/octet-stream when you pass in a image directly 32 | headers = {'Content-Type': 'application/octet-stream', 33 | 'Ocp-Apim-Subscription-Key': subscription_key} 34 | 35 | # According to the documentation for the analyze image function 36 | # we use HTTP POST to call this function 37 | response = requests.post(address, headers=headers, params=parameters, data=image_data) 38 | 39 | # Raise an exception if the call returns an error code 40 | response.raise_for_status() 41 | 42 | # Display the JSON results returned in their raw JSON format 43 | results = response.json() 44 | print(json.dumps(results)) 45 | 46 | # Print out all the tags in the description 47 | print() 48 | print('all tags') 49 | for item in results['description']['tags']: 50 | print(item) 51 | 52 | # print out the first tag in the description 53 | print() 54 | print('first_tag') 55 | print(results['description']['tags'][0]) 56 | 57 | 58 | -------------------------------------------------------------------------------- /17 - JSON/read_json.py: -------------------------------------------------------------------------------- 1 | # This code will show you how to call the Computer Vision API from Python 2 | # You can find documentation on the Computer Vision Analyze Image method here 3 | # https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fa 4 | 5 | # Use the requests library to simplify making a REST API call from Python 6 | import requests 7 | 8 | # We will need the json library to read the data passed back 9 | # by the web service 10 | import json 11 | 12 | # We need the address of our Computer vision service 13 | vision_service_address = "https://canadacentral.api.cognitive.microsoft.com/vision/v2.0/" 14 | # Add the name of the function we want to call to the address 15 | address = vision_service_address + "analyze" 16 | 17 | # According to the documentation for the analyze image function 18 | # There are three optional parameters: language, details & visualFeatures 19 | parameters = {'visualFeatures':'Description,Color', 20 | 'language':'en'} 21 | 22 | # We need the key to access our Computer Vision Service 23 | subscription_key = "cf229a23c3054905b5a8ad512edfa9dd" 24 | 25 | # Open the image file to get a file object containing the image to analyze 26 | image_path = "./TestImages/PolarBear.jpg" 27 | image_data = open(image_path, 'rb').read() 28 | 29 | # According to the documentation for the analyze image function 30 | # we need to specify the subscription key and the content type 31 | # in the HTTP header. Content-Type is application/octet-stream when you pass in a image directly 32 | headers = {'Content-Type': 'application/octet-stream', 33 | 'Ocp-Apim-Subscription-Key': subscription_key} 34 | 35 | # According to the documentation for the analyze image function 36 | # we use HTTP POST to call this function 37 | response = requests.post(address, headers=headers, params=parameters, data=image_data) 38 | 39 | # Raise an exception if the call returns an error code 40 | response.raise_for_status() 41 | 42 | # Display the JSON results returned 43 | results = response.json() 44 | print(json.dumps(results)) 45 | 46 | print('requestId') 47 | print (results['requestId']) 48 | 49 | print('dominantColorBackground') 50 | print(results['color']['dominantColorBackground']) 51 | 52 | print('first_tag') 53 | print(results['description']['tags'][0]) 54 | 55 | for item in results['description']['tags']: 56 | print(item) 57 | 58 | print('caption text') 59 | print(results['description']['captions'][0]['text']) 60 | 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | env 2 | 3 | # Created by https://www.gitignore.io/api/python,visualstudiocode 4 | # Edit at https://www.gitignore.io/?templates=python,visualstudiocode 5 | 6 | ### Python ### 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | *.py[cod] 10 | *$py.class 11 | 12 | # C extensions 13 | *.so 14 | 15 | # Distribution / packaging 16 | .Python 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | .eggs/ 23 | lib/ 24 | lib64/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | wheels/ 29 | pip-wheel-metadata/ 30 | share/python-wheels/ 31 | *.egg-info/ 32 | .installed.cfg 33 | *.egg 34 | MANIFEST 35 | 36 | # PyInstaller 37 | # Usually these files are written by a python script from a template 38 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 39 | *.manifest 40 | *.spec 41 | 42 | # Installer logs 43 | pip-log.txt 44 | pip-delete-this-directory.txt 45 | 46 | # Unit test / coverage reports 47 | htmlcov/ 48 | .tox/ 49 | .nox/ 50 | .coverage 51 | .coverage.* 52 | .cache 53 | nosetests.xml 54 | coverage.xml 55 | *.cover 56 | .hypothesis/ 57 | .pytest_cache/ 58 | 59 | # Translations 60 | *.mo 61 | *.pot 62 | 63 | # Django stuff: 64 | *.log 65 | local_settings.py 66 | db.sqlite3 67 | 68 | # Flask stuff: 69 | instance/ 70 | .webassets-cache 71 | 72 | # Scrapy stuff: 73 | .scrapy 74 | 75 | # Sphinx documentation 76 | docs/_build/ 77 | 78 | # PyBuilder 79 | target/ 80 | 81 | # Jupyter Notebook 82 | .ipynb_checkpoints 83 | 84 | # IPython 85 | profile_default/ 86 | ipython_config.py 87 | 88 | # pyenv 89 | .python-version 90 | 91 | # pipenv 92 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 93 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 94 | # having no cross-platform support, pipenv may install dependencies that don’t work, or not 95 | # install all needed dependencies. 96 | #Pipfile.lock 97 | 98 | # celery beat schedule file 99 | celerybeat-schedule 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | ### VisualStudioCode ### 132 | .vscode/* 133 | !.vscode/settings.json 134 | !.vscode/tasks.json 135 | !.vscode/launch.json 136 | !.vscode/extensions.json 137 | 138 | ### VisualStudioCode Patch ### 139 | # Ignore all local history of files 140 | .history 141 | 142 | # End of https://www.gitignore.io/api/python,visualstudiocode 143 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [many more](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [definition](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting started with Python 2 | 3 | ## Overview 4 | 5 | The series of videos on Channel 9 is designed to help get you up to speed on Python. If you're a beginning developer who's looking to add Python to your quiver of languages, or trying to get started on a data science or web project, these videos can help teach you the foundation necessary to walk through a quick start or other tutorial. 6 | 7 | ### What you'll learn 8 | 9 | - The basics of Python 10 | - Starting a project 11 | - Common syntax 12 | - Package management 13 | 14 | ### What we don't cover 15 | 16 | - Class design and inheritance 17 | - Asynchronous programming 18 | - Basics of programming 19 | 20 | ## Prerequisites 21 | 22 | - [An understanding of Git](https://git-scm.com/book/en/v1/Getting-Started) 23 | - Light experience with another programming language, such as [JavaScript](https://www.edx.org/course/javascript-introduction) 24 | 25 | ## Next steps 26 | 27 | As the goal of this course is to help get you up to speed on Python so you can work through a quick start, the next step after completing the videos is to follow a tutorial! Here's a few of our favorites: 28 | 29 | - [Quickstart: Detect faces in an image using the Face REST API and Python](https://docs.microsoft.com/en-us/azure/cognitive-services/face/QuickStarts/Python?WT.mc_id=python-c9-niner) 30 | - [Quickstart: Analyze a local image using the Computer Vision REST API and Python](https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts/python-disk?WT.mc_id=python-c9-niner) 31 | - [Quickstart: Using the Python REST API to call the Text Analytics Cognitive Service](https://docs.microsoft.com/en-us/azure/cognitive-services/Text-Analytics/quickstarts/python?WT.mc_id=python-c9-niner) 32 | - [Tutorial: Build a Flask app with Azure Cognitive Services](https://docs.microsoft.com/en-us/azure/cognitive-services/translator/tutorial-build-flask-app-translation-synthesis) 33 | - [Flask tutorial in Visual Studio Code](https://code.visualstudio.com/docs/python/tutorial-flask?WT.mc_id=python-c9-niner) 34 | - [Django tutorial in Visual Studio Code](https://code.visualstudio.com/docs/python/tutorial-django?WT.mc_id=python-c9-niner) 35 | 36 | ## Contributing 37 | 38 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 39 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 40 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 41 | 42 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 43 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 44 | provided by the bot. You will only need to do this once across all repos using our CLA. 45 | 46 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 47 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 48 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 49 | --------------------------------------------------------------------------------