From 550c36b8df51dfd0a84031370d299aafa6a5a416 Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Thu, 21 Sep 2023 12:59:15 +0000 Subject: [PATCH 1/8] adfsdf --- python-for-beginners/02 - Print/coding_challenge.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python-for-beginners/02 - Print/coding_challenge.py b/python-for-beginners/02 - Print/coding_challenge.py index 50b79e8c..1834dc2a 100644 --- a/python-for-beginners/02 - Print/coding_challenge.py +++ b/python-for-beginners/02 - Print/coding_challenge.py @@ -2,14 +2,14 @@ # See if you can fix the code below # print the message -print('Why won't this line of code print') +print("Why won't this line of code print") # print the message -prnit('This line fails too!') +print('This line fails too!') # print the message -print "I think I know how to fix this one" +print("I think I know how to fix this one") # print the name entered by the user -input('Please tell me your name: ') +name = input('Please tell me your name: ') print(name) From e49cbdf8336ccf83222d8c8f1cb98207b1c8bb3d Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:20:04 +0000 Subject: [PATCH 2/8] Commit 4 --- .../03 - Comments/enable_pin.py | 1 + .../04 - String variables/code_challenge.py | 3 +++ .../04 - String variables/format_strings.py | 3 +++ .../05 - Numeric variables/code_challenge.py | 3 +++ .../combining_strings_and_numbers.py | 2 +- .../06 - Dates/code_challenge.py | 11 ++++++++- .../06 - Dates/code_challenge_solution.py | 4 +++- .../code_challenge.py | 5 ++-- .../code_challenge.py | 16 ++++++++++++- .../multiple_if_statements.py | 6 +++-- .../boolean_variables.py | 2 +- .../code_challenge.py | 24 ++++++++++++++++++- 12 files changed, 69 insertions(+), 11 deletions(-) diff --git a/python-for-beginners/03 - Comments/enable_pin.py b/python-for-beginners/03 - Comments/enable_pin.py index 12fd95ea..365237b9 100644 --- a/python-for-beginners/03 - Comments/enable_pin.py +++ b/python-for-beginners/03 - Comments/enable_pin.py @@ -5,6 +5,7 @@ # we cover methods in a separate module def enable_pin(user, pin): print('pin enabled') + print(user + " " + pin) # Set current_user and pin to test values current_user = 'TEST123' diff --git a/python-for-beginners/04 - String variables/code_challenge.py b/python-for-beginners/04 - String variables/code_challenge.py index cdc417d1..7a95d580 100644 --- a/python-for-beginners/04 - String variables/code_challenge.py +++ b/python-for-beginners/04 - String variables/code_challenge.py @@ -4,3 +4,6 @@ # Make sure you have a space between first and last name # Make sure the first letter of first name and last name is uppercase # Make sure the rest of the name is lowercase +firstName = input("Fist name please?") +lastName = input("Last name please?") +print(firstName.capitalize()+" "+lastName.capitalize()) diff --git a/python-for-beginners/04 - String variables/format_strings.py b/python-for-beginners/04 - String variables/format_strings.py index 6b795886..9e3c9815 100644 --- a/python-for-beginners/04 - String variables/format_strings.py +++ b/python-for-beginners/04 - String variables/format_strings.py @@ -6,3 +6,6 @@ # the first letter uppercase and the rest of the word lowercase print ('Hello ' + first_name.capitalize() + ' ' \ + last_name.capitalize()) + + +print(f"Hola {input('First name?')} {input('Last name?')}") \ No newline at end of file diff --git a/python-for-beginners/05 - Numeric variables/code_challenge.py b/python-for-beginners/05 - Numeric variables/code_challenge.py index 48726c5a..da893343 100644 --- a/python-for-beginners/05 - Numeric variables/code_challenge.py +++ b/python-for-beginners/05 - Numeric variables/code_challenge.py @@ -4,3 +4,6 @@ # Print 'first number + second number = answer' # For example if someone enters 4 and 6 the output should read # 4 + 6 = 10 +number1 = input('Number 1 ') +number2 = input('Number 2 ') +print(f'{number1} + {number2} = {str(int(number2)+int(number1))}') \ No newline at end of file diff --git a/python-for-beginners/05 - Numeric variables/combining_strings_and_numbers.py b/python-for-beginners/05 - Numeric variables/combining_strings_and_numbers.py index 8a654ee5..787a5422 100644 --- a/python-for-beginners/05 - Numeric variables/combining_strings_and_numbers.py +++ b/python-for-beginners/05 - Numeric variables/combining_strings_and_numbers.py @@ -6,7 +6,7 @@ # The + operator can either add two numbers or it can concatenate two strings # it does not know what to do when you pass it one number and one string # This line of code will cause an error -print(days_in_feb + ' days in February') +#print(days_in_feb + ' days in February') # You need to convert the number to a string to display the value # This line of code will work diff --git a/python-for-beginners/06 - Dates/code_challenge.py b/python-for-beginners/06 - Dates/code_challenge.py index 0faa1338..fa72415a 100644 --- a/python-for-beginners/06 - Dates/code_challenge.py +++ b/python-for-beginners/06 - Dates/code_challenge.py @@ -1,4 +1,13 @@ # print today's date # print yesterday's date # ask a user to enter a date -# print the date one week from the date entered \ No newline at end of file +# print the date one week from the date entered +from datetime import datetime, timedelta + +currentdate = datetime.now() + +print(str(currentdate - timedelta(days=1))) +print(str(currentdate + timedelta(weeks=1))) + +print(f"{currentdate:%d/%m/%Y}") +print('{:%d - %m - %Y}'.format(currentdate)) \ No newline at end of file diff --git a/python-for-beginners/06 - Dates/code_challenge_solution.py b/python-for-beginners/06 - Dates/code_challenge_solution.py index 1c548d23..d26c78fc 100644 --- a/python-for-beginners/06 - Dates/code_challenge_solution.py +++ b/python-for-beginners/06 - Dates/code_challenge_solution.py @@ -16,4 +16,6 @@ # print the date one week from the date entered one_week = timedelta(weeks=1) one_week_later = date_entered + one_week -print('One week later it will be: ' + str(one_week_later)) \ No newline at end of file +print('One week later it will be: ' + str(one_week_later)) + + diff --git a/python-for-beginners/08 - Handling conditions/code_challenge.py b/python-for-beginners/08 - Handling conditions/code_challenge.py index 4d1a5155..e01735f7 100644 --- a/python-for-beginners/08 - Handling conditions/code_challenge.py +++ b/python-for-beginners/08 - Handling conditions/code_challenge.py @@ -4,9 +4,8 @@ # If I enter 0.50 I should see the message "Tax rate is: 0" price = input('how much did you pay? ') -if price > 1.00: +if float(price) >= 1.00: tax = .07 - print('Tax rate is: ' + str(tax)) -else +else: tax = 0 print('Tax rate is: ' + str(tax)) \ No newline at end of file diff --git a/python-for-beginners/09 - Handling multiple conditions/code_challenge.py b/python-for-beginners/09 - Handling multiple conditions/code_challenge.py index 53e7c6b1..bac6958c 100644 --- a/python-for-beginners/09 - Handling multiple conditions/code_challenge.py +++ b/python-for-beginners/09 - Handling multiple conditions/code_challenge.py @@ -11,4 +11,18 @@ # Bob should be in room AB # Charlie should be in room C # Khalid Haque should be in room OTHER -# Xin Zhao should be in room Z \ No newline at end of file +# Xin Zhao should be in room Z +name = input('What is your name? ') + +if name.capitalize().startswith('A') or name.capitalize().startswith('B'): + print('Go to room AB') +elif name.capitalize().startswith('C'): + print('Go to room CD') +else: + lastName = input('What is your last name? ') + if lastName.capitalize().startswith('Z'): + print('Go to room Z') + else: + print('Go to room OTHER') + + \ No newline at end of file diff --git a/python-for-beginners/09 - Handling multiple conditions/multiple_if_statements.py b/python-for-beginners/09 - Handling multiple conditions/multiple_if_statements.py index bd0983a0..026afe6b 100644 --- a/python-for-beginners/09 - Handling multiple conditions/multiple_if_statements.py +++ b/python-for-beginners/09 - Handling multiple conditions/multiple_if_statements.py @@ -4,8 +4,10 @@ if province == 'Alberta': tax = 0.05 -if province == 'Nunavut': +elif province == 'Nunavut': tax = 0.05 -if province == 'Ontario': +elif province == 'Ontario': tax = 0.13 +else: + tax = .15 print(tax) diff --git a/python-for-beginners/10 - Complex conditon checks/boolean_variables.py b/python-for-beginners/10 - Complex conditon checks/boolean_variables.py index 74949e43..806d9548 100644 --- a/python-for-beginners/10 - Complex conditon checks/boolean_variables.py +++ b/python-for-beginners/10 - Complex conditon checks/boolean_variables.py @@ -11,5 +11,5 @@ # Somewhere later in your code if you need to check if students is # on honour roll, all I need to do is check the boolean variable # I set earlier in my code -if honour_roll: +if not honour_roll: print('You made honour roll') diff --git a/python-for-beginners/10 - Complex conditon checks/code_challenge.py b/python-for-beginners/10 - Complex conditon checks/code_challenge.py index 3ffa8064..b6487850 100644 --- a/python-for-beginners/10 - Complex conditon checks/code_challenge.py +++ b/python-for-beginners/10 - Complex conditon checks/code_challenge.py @@ -21,4 +21,26 @@ # first name: ReallyLongFirstName last name: Ibach # output: R. Ibach # first name: ReallyLongFirstName last name: ReallyLongLastName -# output: ReallyLongLastName \ No newline at end of file +# output: ReallyLongLastName + +name = input('What is your name? ') +lastName = input('What is your last name? ') + + +if len(name)<10: + nameLessTen = True +else: + nameLessTen = False + +if len(lastName)<10: + lastNameLessTen = True +else: + lastNameLessTen = False + +if nameLessTen and lastNameLessTen: + print(name + ' ' + lastName) +elif not nameLessTen and lastNameLessTen < 10: + print(name[0:1] + '. '+lastName) +elif nameLessTen and not lastNameLessTen: + print(name + ' '+lastName[0:1]+'.') +else: print(lastName) From db08155e3590ebb10a1d70b031a2633d53e5f975 Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:21:38 +0000 Subject: [PATCH 3/8] aaa --- .../04 - String variables/string_functions.py | 2 ++ python-for-beginners/11 - Collections/arrays.py | 2 +- .../11 - Collections/common-operations.py | 3 +++ python-for-beginners/11 - Collections/ranges.py | 2 +- python-for-beginners/12 - Loops/for.py | 6 +++++- python-for-beginners/12 - Loops/number.py | 2 +- .../13 - Functions/code_challenge.py | 16 ++++++++++++++++ 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/python-for-beginners/04 - String variables/string_functions.py b/python-for-beginners/04 - String variables/string_functions.py index c89b6bd5..b235f83b 100644 --- a/python-for-beginners/04 - String variables/string_functions.py +++ b/python-for-beginners/04 - String variables/string_functions.py @@ -15,3 +15,5 @@ # count will count the number of occurrences of the value specified # in the string, in this case how many times the letter 'a' appears print(sentence.count('a')) + +print(sentence[5:7]) diff --git a/python-for-beginners/11 - Collections/arrays.py b/python-for-beginners/11 - Collections/arrays.py index 3c0a2250..abc65d44 100644 --- a/python-for-beginners/11 - Collections/arrays.py +++ b/python-for-beginners/11 - Collections/arrays.py @@ -1,5 +1,5 @@ from array import array -scores = array('d') +scores = array('i') scores.append(97) scores.append(98) print(scores) \ No newline at end of file diff --git a/python-for-beginners/11 - Collections/common-operations.py b/python-for-beginners/11 - Collections/common-operations.py index f5e4c9ad..c568fd43 100644 --- a/python-for-beginners/11 - Collections/common-operations.py +++ b/python-for-beginners/11 - Collections/common-operations.py @@ -1,4 +1,7 @@ names = ['Christopher', 'Susan'] print(len(names)) # Get the number of items names.insert(0, 'Bill') # Insert before index +names.append('Nacho') +print(names) +names.sort() print(names) diff --git a/python-for-beginners/11 - Collections/ranges.py b/python-for-beginners/11 - Collections/ranges.py index fbc6dd46..7efcbe65 100644 --- a/python-for-beginners/11 - Collections/ranges.py +++ b/python-for-beginners/11 - Collections/ranges.py @@ -1,5 +1,5 @@ names = ['Susan', 'Christopher', 'Bill'] -presenters = names[0:2] # Get the first two items +presenters = names[:2] # Get the first two items # Starting index and number of items to retrieve print(names) diff --git a/python-for-beginners/12 - Loops/for.py b/python-for-beginners/12 - Loops/for.py index 90bf46a5..a2b0e7a5 100644 --- a/python-for-beginners/12 - Loops/for.py +++ b/python-for-beginners/12 - Loops/for.py @@ -1,2 +1,6 @@ -for name in ['Christopher', 'Susan']: +names = ['Christopher', 'Susan'] +for name in names: print(name) + +for index in range(0,len(names)): + print(names[index]) diff --git a/python-for-beginners/12 - Loops/number.py b/python-for-beginners/12 - Loops/number.py index b9d4caad..2e38999e 100644 --- a/python-for-beginners/12 - Loops/number.py +++ b/python-for-beginners/12 - Loops/number.py @@ -2,5 +2,5 @@ # First parameter is the starter # Second indicates the number of numbers to create # range(0, 2) creates [0, 1] -for index in range(0, 2): +for index in range(3, 5): print(index) diff --git a/python-for-beginners/13 - Functions/code_challenge.py b/python-for-beginners/13 - Functions/code_challenge.py index 1d82012c..e5e4fa8b 100644 --- a/python-for-beginners/13 - Functions/code_challenge.py +++ b/python-for-beginners/13 - Functions/code_challenge.py @@ -15,3 +15,19 @@ # BONUS: Test your function with the values 6, 4 and divide # Have your function return an error message when invalid values are received +def calculator(x,y,operator): + result = 0 + if operator.lower()=='add': + result = x + y + elif operator.lower()=='substract': + result = x - y + elif operator.lower()=='divide': + result = x / y + + return result + +print(calculator(6,4,'add')) + +print(calculator(6,4,'substract')) + +print(calculator(6,4,'divide')) \ No newline at end of file From 23b30d3de02e6429126bdc3fb90b87f25866e7b8 Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:29:53 +0000 Subject: [PATCH 4/8] commit --- .gitignore | 1 + .vscode/settings.json | 3 +++ .../01 - Formatting and linting/good.py | 14 ++++++++------ .../02 - Lambdas/lambda_sorter.py | 4 ++-- .../02 - Lambdas/method_sorter.py | 6 +++++- .../03 - Classes/basic_class.py | 5 +++-- .../03 - Classes/properties_class.py | 12 ++++++------ .../print_time_function_fix_import.py | 2 +- .../get_initials_default_values.py | 4 +++- python-for-beginners/15 - Packages/helpers.py | 7 +++++-- .../15 - Packages/import_module.py | 2 +- python-for-beginners/16 - Calling APIs/call_api.py | 4 ++-- python-for-beginners/17 - JSON/app.py | 6 ++++++ .../17 - JSON/create_json_from_dict.py | 2 ++ .../17 - JSON/create_json_with_list.py | 5 ++++- .../17 - JSON/create_json_with_nested_dict.py | 3 ++- python-for-beginners/17 - JSON/read_json.py | 2 +- 17 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 python-for-beginners/17 - JSON/app.py diff --git a/.gitignore b/.gitignore index 47de0432..2816e595 100644 --- a/.gitignore +++ b/.gitignore @@ -138,5 +138,6 @@ dmypy.json ### VisualStudioCode Patch ### # Ignore all local history of files .history +.env # End of https://www.gitignore.io/api/python,visualstudiocode diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..f2d90cbd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.linting.enabled": true +} \ No newline at end of file diff --git a/more-python-for-beginners/01 - Formatting and linting/good.py b/more-python-for-beginners/01 - Formatting and linting/good.py index 3faba59a..63aca717 100644 --- a/more-python-for-beginners/01 - Formatting and linting/good.py +++ b/more-python-for-beginners/01 - Formatting and linting/good.py @@ -1,10 +1,12 @@ def print_hello(name: str) -> str: - """ - Greets the user by name - + """ + Greets the user by name Parameters: - name (str): The name of the user + name (str): The name of the user Returns: - str: The greeting + str: The greeting """ - print('Hello, ' + name) + print("Hello, " + name) + + +print_hello("Nacho") diff --git a/more-python-for-beginners/02 - Lambdas/lambda_sorter.py b/more-python-for-beginners/02 - Lambdas/lambda_sorter.py index ad7878f5..ea97e383 100644 --- a/more-python-for-beginners/02 - Lambdas/lambda_sorter.py +++ b/more-python-for-beginners/02 - Lambdas/lambda_sorter.py @@ -9,6 +9,6 @@ print(presenters) # Sort by length of name (shortest to longest) -presenters.sort(key=lambda item: len(item['name'])) +presenters.sort(key=lambda item: len(item['name']),reverse=False) print('-- length --') -print(presenters) + diff --git a/more-python-for-beginners/02 - Lambdas/method_sorter.py b/more-python-for-beginners/02 - Lambdas/method_sorter.py index 40f296c6..27acde61 100644 --- a/more-python-for-beginners/02 - Lambdas/method_sorter.py +++ b/more-python-for-beginners/02 - Lambdas/method_sorter.py @@ -1,3 +1,5 @@ +import operator + def sorter(item): return item['name'] @@ -7,4 +9,6 @@ def sorter(item): {'name': 'Christopher', 'age': 47} ] presenters.sort(key=sorter) -print(presenters) + +l = list(map(operator.itemgetter('name'),presenters)) +print(l) diff --git a/more-python-for-beginners/03 - Classes/basic_class.py b/more-python-for-beginners/03 - Classes/basic_class.py index 74576195..03676be3 100644 --- a/more-python-for-beginners/03 - Classes/basic_class.py +++ b/more-python-for-beginners/03 - Classes/basic_class.py @@ -2,10 +2,11 @@ class Presenter(): def __init__(self, name): # Constructor self.name = name + def say_hello(self): # method print('Hello, ' + self.name) -presenter = Presenter('Chris') -presenter.name = 'Christopher' +presenter = Presenter('Nacho') +#presenter.name = 'Christopher' presenter.say_hello() \ No newline at end of file diff --git a/more-python-for-beginners/03 - Classes/properties_class.py b/more-python-for-beginners/03 - Classes/properties_class.py index df259cb3..6be7d1db 100644 --- a/more-python-for-beginners/03 - Classes/properties_class.py +++ b/more-python-for-beginners/03 - Classes/properties_class.py @@ -1,18 +1,18 @@ class Presenter(): def __init__(self, name): # Constructor - self.name = name + self.name3 = name @property - def name(self): + def name3(self): print('Retrieving name...') return self.__name - @name.setter - def name(self, value): + @name3.setter + def name3(self, value): # cool validation here print('Validating name...') self.__name = value presenter = Presenter('Chris') -presenter.name = 'Christopher' -print(presenter.name) \ No newline at end of file +presenter.name3 = 'Christopher' +print(presenter.name3) \ No newline at end of file diff --git a/python-for-beginners/13 - Functions/print_time_function_fix_import.py b/python-for-beginners/13 - Functions/print_time_function_fix_import.py index 2dd7d759..116f9bc5 100644 --- a/python-for-beginners/13 - Functions/print_time_function_fix_import.py +++ b/python-for-beginners/13 - Functions/print_time_function_fix_import.py @@ -1,5 +1,5 @@ # Import datetime class from datetime library to simplify calls to datetime.now() -from datetime import datetime +from datetime import * # Create a function called print_time # This function will print the message and current time diff --git a/python-for-beginners/14 - Function parameters/get_initials_default_values.py b/python-for-beginners/14 - Function parameters/get_initials_default_values.py index 40d68f13..0a8279e9 100644 --- a/python-for-beginners/14 - Function parameters/get_initials_default_values.py +++ b/python-for-beginners/14 - Function parameters/get_initials_default_values.py @@ -18,4 +18,6 @@ def get_initial(name, force_uppercase=True): # not passing a value for force_uppercase so default value is used first_name_initial = get_initial(first_name) -print('Your initial is: ' + first_name_initial) \ No newline at end of file +print('Your initial is: ' + first_name_initial) + +print('Your initial is: ' + get_initial(first_name,False)) \ No newline at end of file diff --git a/python-for-beginners/15 - Packages/helpers.py b/python-for-beginners/15 - Packages/helpers.py index 707aeaac..be1a86dd 100644 --- a/python-for-beginners/15 - Packages/helpers.py +++ b/python-for-beginners/15 - Packages/helpers.py @@ -1,4 +1,7 @@ +from pip._vendor.colorama import init,Fore + def display(message, is_warning=False): if is_warning: - print('Warning!!') - print(message) + print(Fore.RED+message) + else: + print(Fore.BLUE,message) diff --git a/python-for-beginners/15 - Packages/import_module.py b/python-for-beginners/15 - Packages/import_module.py index 4b720061..02d0aed6 100644 --- a/python-for-beginners/15 - Packages/import_module.py +++ b/python-for-beginners/15 - Packages/import_module.py @@ -4,7 +4,7 @@ # import all into current namespace from helpers import * -display('Not a warning') +display('Not a warning',True) # import specific items into current namespace from helpers import display diff --git a/python-for-beginners/16 - Calling APIs/call_api.py b/python-for-beginners/16 - Calling APIs/call_api.py index 0bd9ab74..f6c65a2a 100644 --- a/python-for-beginners/16 - Calling APIs/call_api.py +++ b/python-for-beginners/16 - Calling APIs/call_api.py @@ -15,7 +15,7 @@ # You need to update the vision_service_address to the address of # your Computer Vision Service -vision_service_address = "https://canadacentral.api.cognitive.microsoft.com/vision/v2.0/" +vision_service_address = "https://westeurope.api.cognitive.microsoft.com/vision/v2.0/" # Add the name of the function you want to call to the address address = vision_service_address + "analyze" @@ -26,7 +26,7 @@ 'language':'en'} # Open the image file to get a file object containing the image to analyze -image_path = "./TestImages/PolarBear.jpg" +image_path = "./16 - Calling APIs/TestImages/PolarBear.jpg" image_data = open(image_path, "rb").read() # According to the documentation for the analyze image function diff --git a/python-for-beginners/17 - JSON/app.py b/python-for-beginners/17 - JSON/app.py new file mode 100644 index 00000000..ff9a080c --- /dev/null +++ b/python-for-beginners/17 - JSON/app.py @@ -0,0 +1,6 @@ +from dotenv import load_dotenv +load_dotenv() +import os + +database = os.getenv('DATABASE') +print(database) diff --git a/python-for-beginners/17 - JSON/create_json_from_dict.py b/python-for-beginners/17 - JSON/create_json_from_dict.py index 9f5d25b7..c940d8d4 100644 --- a/python-for-beginners/17 - JSON/create_json_from_dict.py +++ b/python-for-beginners/17 - JSON/create_json_from_dict.py @@ -8,5 +8,7 @@ # Convert dictionary to JSON object person_json = json.dumps(person_dict) + + # Print JSON object print(person_json) diff --git a/python-for-beginners/17 - JSON/create_json_with_list.py b/python-for-beginners/17 - JSON/create_json_with_list.py index 1a4cdb02..769e9adb 100644 --- a/python-for-beginners/17 - JSON/create_json_with_list.py +++ b/python-for-beginners/17 - JSON/create_json_with_list.py @@ -11,8 +11,11 @@ # Add list object to dictionary for the languages key person_dict['languages']= languages_list +print(person_dict) + # Convert dictionary to JSON object person_json = json.dumps(person_dict) +person_json_obj = json.loads(json.dumps(person_dict)) # Print JSON object -print(person_json) \ No newline at end of file +print(person_json_obj['last']) \ No newline at end of file diff --git a/python-for-beginners/17 - JSON/create_json_with_nested_dict.py b/python-for-beginners/17 - JSON/create_json_with_nested_dict.py index 8403354c..cf48fbbd 100644 --- a/python-for-beginners/17 - JSON/create_json_with_nested_dict.py +++ b/python-for-beginners/17 - JSON/create_json_with_nested_dict.py @@ -11,6 +11,7 @@ staff_dict['Program Manager']=person_dict # Convert dictionary to JSON object staff_json = json.dumps(staff_dict) +staff_json_obj = json.loads(json.dumps(staff_dict)) # Print JSON object -print(staff_json) \ No newline at end of file +print(staff_json_obj['Program Manager']['City']) \ No newline at end of file diff --git a/python-for-beginners/17 - JSON/read_json.py b/python-for-beginners/17 - JSON/read_json.py index 4346ec41..f82899ac 100644 --- a/python-for-beginners/17 - JSON/read_json.py +++ b/python-for-beginners/17 - JSON/read_json.py @@ -23,7 +23,7 @@ subscription_key = "cf229a23c3054905b5a8ad512edfa9dd" # Open the image file to get a file object containing the image to analyze -image_path = "./TestImages/PolarBear.jpg" +image_path = "./17 - JSON/TestImages/PolarBear.jpg" image_data = open(image_path, 'rb').read() # According to the documentation for the analyze image function From 285490deea9c82b3907169933383b2ba6a4733f2 Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:36:58 +0000 Subject: [PATCH 5/8] Commit --- more-python-for-beginners/02 - Lambdas/lambda_sorter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/more-python-for-beginners/02 - Lambdas/lambda_sorter.py b/more-python-for-beginners/02 - Lambdas/lambda_sorter.py index ea97e383..a07f71d5 100644 --- a/more-python-for-beginners/02 - Lambdas/lambda_sorter.py +++ b/more-python-for-beginners/02 - Lambdas/lambda_sorter.py @@ -8,6 +8,7 @@ print('-- alphabetically --') print(presenters) + # Sort by length of name (shortest to longest) presenters.sort(key=lambda item: len(item['name']),reverse=False) print('-- length --') From 392b7ab75c5279d996c2428b9d9c0ee8235fd969 Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:48:22 +0000 Subject: [PATCH 6/8] Commit --- more-python-for-beginners/05 - Mixins/demo.py | 9 +++++++++ .../06 - Managing the file system/files.py | 2 ++ python-for-beginners/11 - Collections/arrays.py | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/more-python-for-beginners/05 - Mixins/demo.py b/more-python-for-beginners/05 - Mixins/demo.py index 7b5732b6..fc6996bd 100644 --- a/more-python-for-beginners/05 - Mixins/demo.py +++ b/more-python-for-beginners/05 - Mixins/demo.py @@ -23,5 +23,14 @@ def framework(item): if isinstance(item, Loggable): item.log() +class JustLog(Loggable): + def __init__(self): + self.title = 'Just logging' + + + sql_connection = SqlDatabase() +jutlog = JustLog() framework(sql_connection) + +framework(jutlog) diff --git a/more-python-for-beginners/06 - Managing the file system/files.py b/more-python-for-beginners/06 - Managing the file system/files.py index 45a72b17..8c66a8cb 100644 --- a/more-python-for-beginners/06 - Managing the file system/files.py +++ b/more-python-for-beginners/06 - Managing the file system/files.py @@ -1,6 +1,8 @@ from pathlib import Path cwd = Path.cwd() +print('Path ' + cwd.drive) + demo_file = Path(Path.joinpath(cwd, 'demo.txt')) # Get the file name diff --git a/python-for-beginners/11 - Collections/arrays.py b/python-for-beginners/11 - Collections/arrays.py index abc65d44..792cb0b0 100644 --- a/python-for-beginners/11 - Collections/arrays.py +++ b/python-for-beginners/11 - Collections/arrays.py @@ -2,4 +2,7 @@ scores = array('i') scores.append(97) scores.append(98) -print(scores) \ No newline at end of file +print(scores) + +scores2 = ('i',97,98) +print(scores2) \ No newline at end of file From a6bd772a2fc996b751446b3aa6d6d885e25be558 Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:56:25 +0000 Subject: [PATCH 7/8] Commit --- .../06 - Managing the file system/directories.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/more-python-for-beginners/06 - Managing the file system/directories.py b/more-python-for-beginners/06 - Managing the file system/directories.py index e56618e4..c24cc7a3 100644 --- a/more-python-for-beginners/06 - Managing the file system/directories.py +++ b/more-python-for-beginners/06 - Managing the file system/directories.py @@ -4,6 +4,9 @@ # Get the parent directory parent = cwd.parent +print(cwd.dri) + + # Is this a directory? print('\nIs this a directory? ' + str(parent.is_dir())) From 37f28759bc1cc7c7085cad13c92dc2bcc792e204 Mon Sep 17 00:00:00 2001 From: ignaciops00 <138797632+ignaciops00@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:40:01 +0000 Subject: [PATCH 8/8] Comit 4 --- .../06 - Managing the file system/directories.py | 3 +-- .../06 - Managing the file system/files.py | 6 +++--- .../06 - Managing the file system/test.py | 3 +++ .../07 - Reading and writing files/read.py | 2 +- more-python-for-beginners/output.txt | 4 ++++ output.txt | 4 ++++ 6 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 more-python-for-beginners/06 - Managing the file system/test.py create mode 100644 more-python-for-beginners/output.txt create mode 100644 output.txt diff --git a/more-python-for-beginners/06 - Managing the file system/directories.py b/more-python-for-beginners/06 - Managing the file system/directories.py index c24cc7a3..86bc7fba 100644 --- a/more-python-for-beginners/06 - Managing the file system/directories.py +++ b/more-python-for-beginners/06 - Managing the file system/directories.py @@ -4,8 +4,7 @@ # Get the parent directory parent = cwd.parent -print(cwd.dri) - +print(cwd.parents[0]) # Is this a directory? print('\nIs this a directory? ' + str(parent.is_dir())) diff --git a/more-python-for-beginners/06 - Managing the file system/files.py b/more-python-for-beginners/06 - Managing the file system/files.py index 8c66a8cb..b1743a92 100644 --- a/more-python-for-beginners/06 - Managing the file system/files.py +++ b/more-python-for-beginners/06 - Managing the file system/files.py @@ -1,12 +1,12 @@ from pathlib import Path cwd = Path.cwd() -print('Path ' + cwd.drive) +print(cwd.parents[0]) -demo_file = Path(Path.joinpath(cwd, 'demo.txt')) +demo_file = Path(Path.joinpath(cwd.parents[0], 'demo.txt')) # Get the file name -print('\nfile name: ' + demo_file.name) +print('\nfile name: ' + demo_file.parents[0]) # Get the extension print('\nfile suffix: ' + demo_file.suffix) diff --git a/more-python-for-beginners/06 - Managing the file system/test.py b/more-python-for-beginners/06 - Managing the file system/test.py new file mode 100644 index 00000000..2c082386 --- /dev/null +++ b/more-python-for-beginners/06 - Managing the file system/test.py @@ -0,0 +1,3 @@ +import os + +print(f'Currenty directoy {os.getcwd()}') \ No newline at end of file diff --git a/more-python-for-beginners/07 - Reading and writing files/read.py b/more-python-for-beginners/07 - Reading and writing files/read.py index 2c612b49..b7c0a982 100644 --- a/more-python-for-beginners/07 - Reading and writing files/read.py +++ b/more-python-for-beginners/07 - Reading and writing files/read.py @@ -1,5 +1,5 @@ # Open file demo.txt and read the contents -stream = open('./demo.txt', 'rt') +stream = open('demo.txt', 'rt') print('\nIs this readable? ' + str(stream.readable())) print('\nRead one character : ' + stream.read(1)) print('\nRead to end of line : ' + stream.readline()) diff --git a/more-python-for-beginners/output.txt b/more-python-for-beginners/output.txt new file mode 100644 index 00000000..c21f4641 --- /dev/null +++ b/more-python-for-beginners/output.txt @@ -0,0 +1,4 @@ +Hello world +SusanChristopher +Susan +Christopher \ No newline at end of file diff --git a/output.txt b/output.txt new file mode 100644 index 00000000..c21f4641 --- /dev/null +++ b/output.txt @@ -0,0 +1,4 @@ +Hello world +SusanChristopher +Susan +Christopher \ No newline at end of file