├── 02. Variables, Script, Interactive Shell - state change ├── Notes for this lecture.txt └── sample.py ├── 03. Comments └── comments.py ├── 04. Types of variables └── typeOfVariables.py ├── 05. Arithmetic operators └── arhitmetic-operators.py ├── 06. VAT exercise └── arhitmetic-operators.py ├── 07. Semicolon └── semicolon.py ├── 08. Assigments operators └── assignment-operators.py ├── 09. Playing with strings ├── Bullet Points for Python Basic Section.docx ├── The most useful shortcuts used by programmers.docx └── playing-with-strings.py ├── 10. Importing libraries - what is function └── importing-libraries.py ├── 100. Dunder methods __str__ └── dunder-methods-source-codes.zip ├── 101. Organizing files, rocket board └── organizing-files-source-codes.zip ├── 102. __getitem__ __setitem__ └── getitem-setitem-source-codes.zip ├── 103. Distance between rockets └── distance-between-rockets-rockets-en.zip ├── 104. Static Methods └── static-methods-source-codes.zip ├── 105. setting types of parameters └── setting-types-in-python-source-codes.zip ├── 106. __len__ └── len-source-codes.zip ├── 107. static variables └── static-variables-source-codes.zip ├── 108. exercise - bank account └── bank-account-source-codes.zip ├── 109. returning value like a pro └── returning-value-source-codes.zip ├── 11. Popular mistake with function └── popular-mistake.py ├── 110. Inheritance └── inheritance-source-codes.zip ├── 111. EXERCISE - inheritance on result example └── exercises-inheritance-source-codes.zip ├── 112. EXERCISE - figures - inheritance ├── figures-exercise-source-code.zip └── figures-exercise-source-code │ ├── .vscode │ ├── .ropeproject │ │ └── config.py │ ├── launch.json │ └── settings.json │ ├── myscript.py │ └── result.py ├── 113. Inheritance vs association └── inheritance-vs-assocation-source-codes.zip ├── 114. generator function - yield keyword └── generatorfunction.py ├── 115. EXERCISE Generate infinite amount of numbers multiplied by themselves └── exercisegeneratingnumbers.py ├── 116. send method └── sendmethod.py ├── 12. Downloading data from input ├── EXERCISE - Retrieving and Formatting User Input in Python.docx └── downloading-data.py ├── 13. Comparison operator └── comparison-operator.py ├── 14. Conditional statement └── conditional-statement.py ├── 15. Calculator Exercise ├── EXERCISE - Absolute value of a number.docx └── calculatorenglish.py ├── 16. Values different than zero └── valuesdifferentthanzero.py ├── 17. Logical Operators └── logicaloperators.py ├── 18. Loop while └── loops.py ├── 19. Summing numbers └── loops.py ├── 20. Loop for └── loops.py ├── 21. Break and continue └── break_i_continue.py ├── 22. Guess number exercise └── guess_number.py ├── 23. List └── list.py ├── 24. List 'in', 'not in' └── listain.py ├── 24.1 - Giving secret access - EXERCISE └── sample.py ├── 25. List functions └── listfunctions.py ├── 26. Tuple └── tuple.py ├── 27. Dictionary └── dictionary.py ├── 28. Sets └── set.py ├── 29. Operations on sets └── set.py ├── 30. Nested types └── nested-types.py ├── 31. Processing nested types └── nested-types.py ├── 32. Dict in Dict └── dicindic.py ├── 33. Extracting values from nested dictionaries └── processingdic.py ├── 34. Exercise - dictionary of definitions └── dicexercise.py ├── 35. List comprehension └── list-comprehension.py ├── 36. Generator expressions └── generators.py ├── 37. Dictionary comprehension └── dictionarycomprehension.py ├── 38. Set comprehension └── setcomprehensions.py ├── 39. Exercise with divisible numbers └── practise.py ├── 40. How to create a function └── functions.py ├── 41. Passing more than one argument └── many-parameters.py ├── 42. Return value ├── EXERCISE - Add functions to existing code.docx ├── EXERCISE - Count the area of figures.txt ├── Return and invoke.docx └── return.py ├── 43. Your own module imported ├── SOURCE CODE - YOUR OWN MODULES.zip ├── __pycache__ │ └── figures.cpython-37.pyc ├── figures.py └── main_program.py ├── 43.1. enum ├── __pycache__ │ └── figures.cpython-37.pyc ├── figures.py └── main_program.py ├── 44. EXERCISE Arithmetic Sequence └── arithmeticsequence.py ├── 45. Measuring performance of code ├── Python-for-Beginners-Learn-Python-from-Scratch-master - Shortcut.lnk └── arithmeticsequence.py ├── 46. Function as function argument └── arithmeticsequence.py ├── 47. default arguments ├── defaultarguments.py └── defaultarguments2.py ├── 48. named and unnamed arguments └── namedandunnamedarguments.py ├── 49. EXERCISE - checking if value is in container └── exercise.py ├── 50. Variable Length Argument └── variable-length-argument.py ├── 51. Local vs global scope └── localvsglobalscope.py ├── 52. Mutable vs immutable objects └── mutablevsimmutableobjects.py ├── 52.5 shallow vs deep copy └── shallowvsdeepcopy.py ├── 53. lambda, anonymous functions └── lambdaanonymousfunctions.py ├── 53.1. any fuction exercise ├── EXERICSE - Enumarate() tasks and show them to the user.docx ├── Use the all() function to determine if a person has a required set of skills.docx └── test.py ├── 54. random numbers └── drawingrandomnumbers.py ├── 55. choice └── choice.py ├── 56. shuffle ├── shuffle-en.mp4 └── shuffle.py ├── 57. sample └── sample.py ├── 58. Game drawing chests with gold └── gamedrawingchests.py ├── 59. GAME drawing approximate values to certain value └── drawingapproximatevalues.py ├── 60. Files - opening - saving data ├── openingfiles.py └── test.txt ├── 61. Exceptions, try, finally block ├── openingfiles.py └── test.txt ├── 62. keyword with └── openingfiles.py ├── 63. reading content from file ├── namesurnames.txt └── openingfiles.py ├── 64. seek and tell ├── namesurnames.txt └── seektell.py ├── 65. append - adding new content at the end of file ├── appendingtext.py └── namesurnames.txt ├── 66. a+,w+,r+ ├── additionalfileopeningmodes.py └── namesurnames.txt ├── 67. EXERCISE - names and surnames ├── names.txt ├── namesandsurnames.py ├── namesurnames.txt └── surnames.txt ├── 68. JSON └── json_data_format.py ├── 69. Saving data to JSON format ├── json_data_format.py └── sample.json ├── 70. Loading data from JSON to Python ├── json_data_format.py └── sample.json ├── 71. Pretty printing JSON format in Shell and file ├── prettyprinting.py └── sample.json ├── 72. Installing external package - requests - PIP -PyPi ├── EXERCISE - Filter Pages.DOC ├── Fixes for pip if it's not working.txt └── requests_api.py ├── 73. Loading data from server from JSON file - preface to next EXERCISE ├── jsplaceholder.py └── todos.json ├── 74. Processing JSON data from server ├── jsplaceholder.py └── todos.json ├── 75. Refactoring the code ├── jsplaceholder.py └── todos.json ├── 76. Solution 1 - Retrieving a few users from server ├── jsplaceholder.py ├── todos.json └── users.json ├── 77. Solution 2 - Retrieving a few users from server ├── jsplaceholder.py ├── todos.json └── users.json ├── 78. Solution 3 - Retrieving a few users from server ├── jsplaceholder.py ├── todos.json └── users.json ├── 79. defaultdict └── collection_defaultdict.py ├── 80. What is public API └── public_api.py ├── 81. Getting specific JSON from stackoverflow └── specific_json.py ├── 82. Processing JSON from stack └── processing_json.py ├── 83. datetime - getting records from exactly last week └── gettingrecordlastweek.py ├── 84. cat facts └── catfacts.py ├── 85. apikey - authorization └── apikeyauth.py ├── 86. sending custom header with apikey ├── __pycache__ │ └── settings.cpython-37.pyc ├── apikeyauth.py └── settings.py ├── 87. EXERCISE Cat system - introduction └── catsystem.py ├── 88. POST - adding favourite cat └── catsystem.py ├── 89. DELETE - removing favourite cat └── catsystem.py ├── 90. Setting workspace in VSC ├── python english files.zip └── python english files │ ├── .vscode │ ├── launch.json │ └── settings.json │ └── sample.py ├── 91. linters └── python english files.zip ├── 92. Debugging mode └── sample.py ├── 93. Ligatures └── Useful Resource Links.txt ├── 94. Object oriented programming └── oop-source-codes.zip ├── 95. classes and objects └── what-are-objects-classes-source-codes.zip ├── 96. methods and self └── methods-self-source-codes.zip ├── 97. Constructor - init └── constructor-source-codes.zip ├── 98. EXERCISE - rockets └── rockets-source-code.zip ├── 99. Docstring └── docstring-source-codes.zip ├── LICENSE ├── Quiz Questions.pdf ├── README.md └── Retrievied missing items ├── EXERCISE - Absolute value of a number.pdf ├── EXERCISE - Counting the sum of all arguments.pdf ├── EXERCISE - FileNotFoundError exception.pdf ├── EXERCISE - filter pages to those that open and don't and save them in file.pdf ├── Return & invoke.pdf ├── The most useful shortcuts used by programmers.pdf └── opening_file.py /02. Variables, Script, Interactive Shell - state change/Notes for this lecture.txt: -------------------------------------------------------------------------------- 1 | Notes for this lecture 2 | 3 | https://docs.google.com/document/d/1IKSXMZ__AeSf-uvmJTfnd6Oi9ZtU6um19btmKN_04Zo/edit?usp=sharing -------------------------------------------------------------------------------- /02. Variables, Script, Interactive Shell - state change/sample.py: -------------------------------------------------------------------------------- 1 | a = 5 2 | print(a) 3 | 4 | a = a + 5 5 | print(a) 6 | -------------------------------------------------------------------------------- /03. Comments/comments.py: -------------------------------------------------------------------------------- 1 | # THIS PROGRAM ADDS TWO VARIABLES AND SHOWS UP THE SUM 2 | 3 | ''' 4 | 5 | a = 5 #variable named 'a' 6 | b = 4 #variable named 'b' 7 | 8 | sum = a + b 9 | 10 | print(sum) 11 | 12 | ''' 13 | 14 | a = 3 15 | print(a) 16 | 17 | -------------------------------------------------------------------------------- /04. Types of variables/typeOfVariables.py: -------------------------------------------------------------------------------- 1 | a = 5 # int INTeger 2 | b = 3.14 # float numbers 3 | 4 | 5 | sentence = 'I\'m from Poland' #string - sequence of characters 6 | 7 | isBig = False #bool BOOLEAN 8 | 9 | sizeOfSection = 4 #Every word you start inside variable name should be capitalized 10 | -------------------------------------------------------------------------------- /05. Arithmetic operators/arhitmetic-operators.py: -------------------------------------------------------------------------------- 1 | """ 2 | ARITHMETIC operators 3 | 4 | + add 5 | - subtract 6 | * multiply 7 | / divide 8 | 9 | () - parenthesis - for changing order of math operation 10 | 11 | ** raising 12 | // floor division 13 | % - modulo - the remainder operator (what is left after division) 14 | 15 | 16 | """ 17 | -------------------------------------------------------------------------------- /06. VAT exercise/arhitmetic-operators.py: -------------------------------------------------------------------------------- 1 | """ 2 | ARITHMETIC operators 3 | 4 | + add 5 | - subtract 6 | * multiply 7 | / divide 8 | 9 | () - parenthesis - for changing order of math operation 10 | 11 | 12 | """ 13 | 14 | VAT = 20 15 | calculatedVAT = (1 + VAT / 100) # in RAM 16 | 17 | netPriceOfShoes = 100 18 | netPriceOfTV = 2000 19 | 20 | grossPriceOfShoes = netPriceOfShoes * calculatedVAT 21 | grossPriceOfTV = netPriceOfTV * calculatedVAT 22 | 23 | -------------------------------------------------------------------------------- /07. Semicolon/semicolon.py: -------------------------------------------------------------------------------- 1 | x = 5; y = 2; z = 1 2 | 3 | a,b,c = 1,"test",True 4 | 5 | i = j = k = 1 6 | -------------------------------------------------------------------------------- /08. Assigments operators/assignment-operators.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 4 | += x += 5 it is a short way of writing: x = x + 5 5 | -= x -= 5 it is a short way of writing: x = x - 5 6 | *= x *= 5 it is a short way of writing: x = x * 5 7 | /= x /= 5 it is a short way of writing: x = x / 5 8 | %= x %= 5 it is a short way of writing: x = x % 5 9 | //= x //= 5 it is a short way of writing: x = x // 5 10 | **= x **= 5 it is a short way of writing: x = x ** 5 11 | 12 | 13 | """ 14 | 15 | x = 5 16 | 17 | #x = x + 2 18 | 19 | x -= 2 20 | -------------------------------------------------------------------------------- /09. Playing with strings/Bullet Points for Python Basic Section.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/09. Playing with strings/Bullet Points for Python Basic Section.docx -------------------------------------------------------------------------------- /09. Playing with strings/The most useful shortcuts used by programmers.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/09. Playing with strings/The most useful shortcuts used by programmers.docx -------------------------------------------------------------------------------- /09. Playing with strings/playing-with-strings.py: -------------------------------------------------------------------------------- 1 | name = "Arkadiusz" 2 | lastName = "Włodarczyk" 3 | 4 | fullName = name + " " + lastName 5 | 6 | print(fullName) 7 | 8 | longString = "This is a text that was\ 9 | taken from somewhere This is a text that\ 10 | was taken from somewhere This is a text\ 11 | that was taken from somewhere This is a text\ 12 | that was taken from somewhere This is a text\ 13 | that was taken from somewhere " 14 | 15 | print(name[-1]) 16 | 17 | 18 | link = "http://domain.pl" 19 | -------------------------------------------------------------------------------- /10. Importing libraries - what is function/importing-libraries.py: -------------------------------------------------------------------------------- 1 | name = "arkadiusz" 2 | 3 | print(4) 4 | -------------------------------------------------------------------------------- /100. Dunder methods __str__/dunder-methods-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/100. Dunder methods __str__/dunder-methods-source-codes.zip -------------------------------------------------------------------------------- /101. Organizing files, rocket board/organizing-files-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/101. Organizing files, rocket board/organizing-files-source-codes.zip -------------------------------------------------------------------------------- /102. __getitem__ __setitem__/getitem-setitem-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/102. __getitem__ __setitem__/getitem-setitem-source-codes.zip -------------------------------------------------------------------------------- /103. Distance between rockets/distance-between-rockets-rockets-en.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/103. Distance between rockets/distance-between-rockets-rockets-en.zip -------------------------------------------------------------------------------- /104. Static Methods/static-methods-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/104. Static Methods/static-methods-source-codes.zip -------------------------------------------------------------------------------- /105. setting types of parameters/setting-types-in-python-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/105. setting types of parameters/setting-types-in-python-source-codes.zip -------------------------------------------------------------------------------- /106. __len__/len-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/106. __len__/len-source-codes.zip -------------------------------------------------------------------------------- /107. static variables/static-variables-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/107. static variables/static-variables-source-codes.zip -------------------------------------------------------------------------------- /108. exercise - bank account/bank-account-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/108. exercise - bank account/bank-account-source-codes.zip -------------------------------------------------------------------------------- /109. returning value like a pro/returning-value-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/109. returning value like a pro/returning-value-source-codes.zip -------------------------------------------------------------------------------- /11. Popular mistake with function/popular-mistake.py: -------------------------------------------------------------------------------- 1 | name = "JoHn" 2 | 3 | print(name.capitalize()) 4 | 5 | name = name.capitalize() 6 | 7 | print(name) 8 | -------------------------------------------------------------------------------- /110. Inheritance/inheritance-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/110. Inheritance/inheritance-source-codes.zip -------------------------------------------------------------------------------- /111. EXERCISE - inheritance on result example/exercises-inheritance-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/111. EXERCISE - inheritance on result example/exercises-inheritance-source-codes.zip -------------------------------------------------------------------------------- /112. EXERCISE - figures - inheritance/figures-exercise-source-code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/112. EXERCISE - figures - inheritance/figures-exercise-source-code.zip -------------------------------------------------------------------------------- /112. EXERCISE - figures - inheritance/figures-exercise-source-code/.vscode/.ropeproject/config.py: -------------------------------------------------------------------------------- 1 | # The default ``config.py`` 2 | # flake8: noqa 3 | 4 | 5 | def set_prefs(prefs): 6 | """This function is called before opening the project""" 7 | 8 | # Specify which files and folders to ignore in the project. 9 | # Changes to ignored resources are not added to the history and 10 | # VCSs. Also they are not returned in `Project.get_files()`. 11 | # Note that ``?`` and ``*`` match all characters but slashes. 12 | # '*.pyc': matches 'test.pyc' and 'pkg/test.pyc' 13 | # 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc' 14 | # '.svn': matches 'pkg/.svn' and all of its children 15 | # 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o' 16 | # 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o' 17 | prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject', 18 | '.hg', '.svn', '_svn', '.git', '.tox'] 19 | 20 | # Specifies which files should be considered python files. It is 21 | # useful when you have scripts inside your project. Only files 22 | # ending with ``.py`` are considered to be python files by 23 | # default. 24 | # prefs['python_files'] = ['*.py'] 25 | 26 | # Custom source folders: By default rope searches the project 27 | # for finding source folders (folders that should be searched 28 | # for finding modules). You can add paths to that list. Note 29 | # that rope guesses project source folders correctly most of the 30 | # time; use this if you have any problems. 31 | # The folders should be relative to project root and use '/' for 32 | # separating folders regardless of the platform rope is running on. 33 | # 'src/my_source_folder' for instance. 34 | # prefs.add('source_folders', 'src') 35 | 36 | # You can extend python path for looking up modules 37 | # prefs.add('python_path', '~/python/') 38 | 39 | # Should rope save object information or not. 40 | prefs['save_objectdb'] = True 41 | prefs['compress_objectdb'] = False 42 | 43 | # If `True`, rope analyzes each module when it is being saved. 44 | prefs['automatic_soa'] = True 45 | # The depth of calls to follow in static object analysis 46 | prefs['soa_followed_calls'] = 0 47 | 48 | # If `False` when running modules or unit tests "dynamic object 49 | # analysis" is turned off. This makes them much faster. 50 | prefs['perform_doa'] = True 51 | 52 | # Rope can check the validity of its object DB when running. 53 | prefs['validate_objectdb'] = True 54 | 55 | # How many undos to hold? 56 | prefs['max_history_items'] = 32 57 | 58 | # Shows whether to save history across sessions. 59 | prefs['save_history'] = True 60 | prefs['compress_history'] = False 61 | 62 | # Set the number spaces used for indenting. According to 63 | # :PEP:`8`, it is best to use 4 spaces. Since most of rope's 64 | # unit-tests use 4 spaces it is more reliable, too. 65 | prefs['indent_size'] = 4 66 | 67 | # Builtin and c-extension modules that are allowed to be imported 68 | # and inspected by rope. 69 | prefs['extension_modules'] = [] 70 | 71 | # Add all standard c-extensions to extension_modules list. 72 | prefs['import_dynload_stdmods'] = True 73 | 74 | # If `True` modules with syntax errors are considered to be empty. 75 | # The default value is `False`; When `False` syntax errors raise 76 | # `rope.base.exceptions.ModuleSyntaxError` exception. 77 | prefs['ignore_syntax_errors'] = False 78 | 79 | # If `True`, rope ignores unresolvable imports. Otherwise, they 80 | # appear in the importing namespace. 81 | prefs['ignore_bad_imports'] = False 82 | 83 | # If `True`, rope will insert new module imports as 84 | # `from import ` by default. 85 | prefs['prefer_module_from_imports'] = False 86 | 87 | # If `True`, rope will transform a comma list of imports into 88 | # multiple separate import statements when organizing 89 | # imports. 90 | prefs['split_imports'] = False 91 | 92 | # If `True`, rope will remove all top-level import statements and 93 | # reinsert them at the top of the module when making changes. 94 | prefs['pull_imports_to_top'] = True 95 | 96 | # If `True`, rope will sort imports alphabetically by module name instead 97 | # of alphabetically by import statement, with from imports after normal 98 | # imports. 99 | prefs['sort_imports_alphabetically'] = False 100 | 101 | # Location of implementation of 102 | # rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general 103 | # case, you don't have to change this value, unless you're an rope expert. 104 | # Change this value to inject you own implementations of interfaces 105 | # listed in module rope.base.oi.type_hinting.providers.interfaces 106 | # For example, you can add you own providers for Django Models, or disable 107 | # the search type-hinting in a class hierarchy, etc. 108 | prefs['type_hinting_factory'] = ( 109 | 'rope.base.oi.type_hinting.factory.default_type_hinting_factory') 110 | 111 | 112 | def project_opened(project): 113 | """This function is called after opening the project""" 114 | # Do whatever you like here! 115 | -------------------------------------------------------------------------------- /112. EXERCISE - figures - inheritance/figures-exercise-source-code/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Current File", 9 | "type": "python", 10 | "request": "launch", 11 | "program": "${file}", 12 | "console": "integratedTerminal" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /112. EXERCISE - figures - inheritance/figures-exercise-source-code/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.linting.flake8Enabled": true, 3 | "python.linting.enabled": true, 4 | "python.linting.flake8Args": [ 5 | "--ignore=W292,W293,W391,W291,E501" 6 | ], 7 | "cSpell.enabled": false, 8 | "code-runner.runInTerminal": true, 9 | "python.pythonPath": "C:\\Users\\video\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe" 10 | } -------------------------------------------------------------------------------- /112. EXERCISE - figures - inheritance/figures-exercise-source-code/myscript.py: -------------------------------------------------------------------------------- 1 | """ 2 |      Create three classes: 3 |      1) Rectangle 4 |      2) Square 5 |      3) Cube 6 |      7 |      a) Create constructors (__init__) 8 |      b) methods calculating the surface_area of a square, rectangle, cube 9 |      c) a method calculating the volume of the cube 10 | 11 |      Consider how you can use inheritance to do this so that you don't repeat the code 12 | """ 13 | 14 | 15 | class Rectangle: 16 | def __init__(self, width, height): 17 | self.width = width 18 | self.height = height 19 | 20 | def count_surface_area(self): 21 | return self.width * self.height 22 | 23 | 24 | class Square(Rectangle): 25 | def __init__(self, sideLength): 26 | super().__init__(sideLength, sideLength) 27 | 28 | 29 | class Cube(Square): 30 | def count_surface_area(self): 31 | return super().count_surface_area() * 6 32 | 33 | def count_volume(self): 34 | return super().count_surface_area() * self.height 35 | 36 | 37 | cube = Cube(2) 38 | 39 | print(cube.count_volume()) 40 | -------------------------------------------------------------------------------- /112. EXERCISE - figures - inheritance/figures-exercise-source-code/result.py: -------------------------------------------------------------------------------- 1 | class Result: 2 | def __init__(self, message, value=None): 3 | self.isSuccess = None 4 | self.message = message 5 | self.value = value 6 | 7 | def is_ok(self): 8 | return self.isSuccess 9 | 10 | 11 | class Ok(Result): 12 | def __init__(self, message, value=None): 13 | super().__init__(message, value) 14 | self.isSuccess = True 15 | 16 | 17 | class Error(Result): 18 | def __init__(self, message, value=None): 19 | super().__init__(message, value) 20 | self.isSuccess = False 21 | -------------------------------------------------------------------------------- /113. Inheritance vs association/inheritance-vs-assocation-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/113. Inheritance vs association/inheritance-vs-assocation-source-codes.zip -------------------------------------------------------------------------------- /114. generator function - yield keyword/generatorfunction.py: -------------------------------------------------------------------------------- 1 | """ 2 | yield - means - supply, provide, generate 3 | 4 | iterator 5 | 6 | iterate on 7 | 8 | GO THROUGH it 9 | 10 | GENERATOR FUNCTION is a function that has a YIELD keyword 11 | """ 12 | 13 | def generate_even_numbers(): 14 | print("start") 15 | for element in range(400): 16 | print("before yield") 17 | if (element % 2 == 0): 18 | yield element 19 | print("after yield") 20 | 21 | 22 | evenNumbersGenerator = (element 23 | for element in range(400) 24 | if (element % 2 == 0)) 25 | 26 | 27 | numberGenerator = generate_even_numbers() 28 | 29 | def generate_10_numbers(): 30 | x = 0 31 | while x < 10: 32 | yield x 33 | x = x + 1 34 | 35 | generate_10_numbers_expression = (x for x in range(10)) 36 | 37 | print(list(generate_10_numbers())) 38 | print(list(generate_10_numbers())) 39 | print(list(generate_10_numbers())) 40 | 41 | print(list(generate_10_numbers_expression)) 42 | print(list(generate_10_numbers_expression)) 43 | print(list(generate_10_numbers_expression)) 44 | -------------------------------------------------------------------------------- /115. EXERCISE Generate infinite amount of numbers multiplied by themselves/exercisegeneratingnumbers.py: -------------------------------------------------------------------------------- 1 | """ Create a generator function that will generate numbers multiplied 2 | 3 | by themselves 4 | 5 | 1 6 | 7 | 4 8 | 9 | 9 10 | 11 | 16 12 | 13 | 25 14 | 15 | 36 16 | 17 | Generate 20 elements, stop, and then again generate 30 numbers. 18 | 19 | Save each results in the same list and then show it. 20 | """ 21 | 22 | def number_multiplied_by_itself_generator(): 23 | number = 0 24 | while True: 25 | number = number + 1 26 | yield number * number 27 | 28 | 29 | generatedNumbers = [] 30 | 31 | numberGenerator = number_multiplied_by_itself_generator() 32 | 33 | for _ in range(20): 34 | generatedNumbers.append(next(numberGenerator)) 35 | 36 | print(generatedNumbers) 37 | 38 | 39 | """ 40 | MANY INSTRUCTIONS 41 | """ 42 | for _ in range(30): 43 | generatedNumbers.append(next(numberGenerator)) 44 | 45 | print(generatedNumbers) 46 | -------------------------------------------------------------------------------- /116. send method/sendmethod.py: -------------------------------------------------------------------------------- 1 | def number_multiplied_by_itself_generator(): 2 | number = 0 3 | while True: 4 | print("before yield number:", number) 5 | #number = number + 1 6 | number = yield number * number 7 | print("after yield number:", number) 8 | 9 | 10 | 11 | 12 | 13 | generatedNumbers = [] 14 | 15 | numberGenerator = number_multiplied_by_itself_generator() 16 | 17 | numberGenerator.send(None) 18 | #next(numberGenerator) 19 | 20 | for i in range(20): 21 | generatedNumbers.append(numberGenerator.send(i)) 22 | 23 | print(generatedNumbers) 24 | 25 | 26 | 27 | for i in range(30, 50): 28 | generatedNumbers.append(numberGenerator.send(i)) 29 | 30 | print(generatedNumbers) 31 | 32 | -------------------------------------------------------------------------------- /12. Downloading data from input/EXERCISE - Retrieving and Formatting User Input in Python.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/12. Downloading data from input/EXERCISE - Retrieving and Formatting User Input in Python.docx -------------------------------------------------------------------------------- /12. Downloading data from input/downloading-data.py: -------------------------------------------------------------------------------- 1 | print("Program that adds two numbers to each other") 2 | a = int(input("First number: ")) 3 | b = int(input("Second number: ")) #CASTING allows you to change ONE type of variable to another type of variable 4 | 5 | print("Sum of a =", a, "+", "b =", b, "is equal to", a + b) 6 | -------------------------------------------------------------------------------- /13. Comparison operator/comparison-operator.py: -------------------------------------------------------------------------------- 1 | """ 2 | > greater than 3 | < small than 4 | == equal to 5 | != not equal to 6 | >= greater than or equal to 7 | <= small than or equal to 8 | 9 | """ 10 | -------------------------------------------------------------------------------- /14. Conditional statement/conditional-statement.py: -------------------------------------------------------------------------------- 1 | """ 2 | Conditional Statement 3 | 4 | PSEUDO CODE 5 | 6 | if (true/nottrue) 7 | .... 8 | elseif(true/nottrue) 9 | .... 10 | elseif(true/nottrue) 11 | .... 12 | else 13 | .... 14 | 15 | tab button 16 | """ 17 | 18 | a = int(input("First number: ")) 19 | b = int(input("Second number: ")) 20 | 21 | if (a > b): 22 | print("a is greater than b") 23 | elif(a < b): 24 | print("a is lower than b") 25 | else: 26 | print("a is equal b") 27 | -------------------------------------------------------------------------------- /15. Calculator Exercise/EXERCISE - Absolute value of a number.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/15. Calculator Exercise/EXERCISE - Absolute value of a number.docx -------------------------------------------------------------------------------- /15. Calculator Exercise/calculatorenglish.py: -------------------------------------------------------------------------------- 1 | ''' 2 | ADD SUBTRACT MULTIPLY DIVIDE 3 | 4 | CALCULATOR 5 | ''' 6 | 7 | menuOption = input("+ - ADD 2 - SUBTRACT * - MULTIPLY / - DIVIDE: ") 8 | 9 | firstNumber = int(input("First number: ")) 10 | secondNumber = int(input("Second number: ")) 11 | 12 | if (menuOption == '+'): 13 | print(firstNumber + secondNumber) 14 | elif (menuOption == '-'): 15 | print(firstNumber - secondNumber) 16 | elif (menuOption == '*'): 17 | print(firstNumber * secondNumber) 18 | elif (menuOption == '/'): 19 | if (secondNumber == 0): 20 | print('Division by zero - you cannot do it!') 21 | else: 22 | print(firstNumber / secondNumber) 23 | else: 24 | print("You have typed something unexpected") 25 | -------------------------------------------------------------------------------- /16. Values different than zero/valuesdifferentthanzero.py: -------------------------------------------------------------------------------- 1 | a = 0 2 | b = 7 3 | 4 | if (a): 5 | print("test") 6 | -------------------------------------------------------------------------------- /17. Logical Operators/logicaloperators.py: -------------------------------------------------------------------------------- 1 | '''number = int(input("Type a number and I will tell if it's between 1 and 10: ")) 2 | 3 | if (number > 1 and number < 10): 4 | print("number between 1 and 10") 5 | ''' 6 | 7 | a = 5 8 | b = 2 9 | 10 | if (not(a > b and b == 5)): 11 | print("test") 12 | 13 | 14 | ''' 15 | LOGICAL operators 16 | 17 | True False 18 | 19 | and 20 | 21 | True True - True 22 | True False - False 23 | False True - False 24 | False False - False 25 | 26 | Conjuction is TRUE only when BOTH expressions are TRUE 27 | 28 | or 29 | 30 | True True - True 31 | True False - True 32 | False True - True 33 | False False - False 34 | 35 | Alternative is FALSE only when BOTH expressions are FALSE 36 | 37 | not - no 38 | 39 | True to False 40 | False to True 41 | 42 | 43 | ''' 44 | -------------------------------------------------------------------------------- /18. Loop while/loops.py: -------------------------------------------------------------------------------- 1 | #LOOP ctrl + C 2 | 3 | number = 0 4 | 5 | while number <= 5: 6 | print(number) 7 | number += 1 8 | -------------------------------------------------------------------------------- /19. Summing numbers/loops.py: -------------------------------------------------------------------------------- 1 | result = 0 2 | 3 | i = 0 4 | while i < 4: 5 | nr = int(input("Please give me the number: ")) 6 | result += nr 7 | i += 1 8 | print("The result of adding numbers is: ", result) 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /20. Loop for/loops.py: -------------------------------------------------------------------------------- 1 | result = 0 2 | """ 3 | i = 0 4 | while i < 4: 5 | nr = int(input("Please give me the number: ")) 6 | result += nr 7 | i += 1 8 | 9 | print("The result of adding numbers is: ", result) 10 | """ 11 | 12 | 13 | for i in range(1000): 14 | if (i%2 == 0): 15 | print(i, " is even number") 16 | 17 | print("The result of adding numbers is: ", result) 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /21. Break and continue/break_i_continue.py: -------------------------------------------------------------------------------- 1 | """ 2 | break (leaves loop entirely) 3 | 4 | continue (leaves current iteration (repetition of loop) and CONTINUE) 5 | """ 6 | 7 | result = 0 8 | 9 | i = 0 10 | 11 | while i < 3: 12 | x = int(input("Enter a positive number: ")) 13 | if (x > 0): 14 | result += x 15 | else: 16 | print("I expected positive number, you gave me a negative number, you are a bad boy!") 17 | continue 18 | print("Current addition result =", result) 19 | i += 1 20 | -------------------------------------------------------------------------------- /22. Guess number exercise/guess_number.py: -------------------------------------------------------------------------------- 1 | "GUESS NUMBER" 2 | 3 | secretNumber = 40 4 | guessedNumber = 0 5 | 6 | while guessedNumber != secretNumber: 7 | guessedNumber = int(input("Guess number: ")) 8 | 9 | if (secretNumber > guessedNumber): 10 | print("It's a bit bigger ;)") 11 | elif (secretNumber < guessedNumber): 12 | print("It's a bit smaller ;(") 13 | else: 14 | print("CONGRATULATION") 15 | 16 | -------------------------------------------------------------------------------- /23. List/list.py: -------------------------------------------------------------------------------- 1 | # What is list? 2 | # How to create it? 3 | # How to change value of elements inside a list? 4 | # How to print values? 5 | # How to print all values at once? 6 | # Why do we need lists at all? ;) 7 | 8 | 9 | names = ["Arkadiusz", "John", "Claire", "Peter", "Jacob"] #5 el 10 | # 0 1 2 3 4 11 | numbers = [1, 4, 51, 42, -5, 20] #6 el 12 | # 0 1 2 3 4 5 13 | 14 | numbers[5] = 30 15 | 16 | for name in names: 17 | print(name) 18 | -------------------------------------------------------------------------------- /24. List 'in', 'not in'/listain.py: -------------------------------------------------------------------------------- 1 | # in 2 | # not in 3 | # operations on list 4 | 5 | names = ["Arkadiusz", "Claire", "Peter", "Jacob"] 6 | numbers = [3, 12, 24, 7, -8] 7 | 8 | if ("John" not in names): 9 | print("Hello John, welcome!") 10 | 11 | if (4 in numbers): 12 | print("Number 4 is inside the list called numbers") 13 | else: 14 | print("Number 4 is not inside the list") 15 | 16 | -------------------------------------------------------------------------------- /24.1 - Giving secret access - EXERCISE/sample.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | You receive a list of people who will be given 'access' to secret information: 4 | names = ['Arkadiusz', 'Chris', 'John'] 5 | 6 | If someone from the 'names' list is provided by the user in the 'name' variable 7 | display: 8 | "Access granted" 9 | 10 | If not write: 11 | "Access denied" 12 | 13 | ''' 14 | 15 | names = ['Arkadiusz', 'Chris', 'John'] 16 | 17 | name = input() 18 | name = name.capitalize() 19 | 20 | if name == "Arkadiusz" or name == "Chris" or name == "John": 21 | print("Access granted") 22 | else: 23 | print("Access denied") 24 | -------------------------------------------------------------------------------- /25. List functions/listfunctions.py: -------------------------------------------------------------------------------- 1 | #len() - length 2 | #.append - adding at the end SINGLLE element 3 | #.extend - extending list by another list 4 | #.insert(index, what) - put in 5 | #.index(what) - return index of 'what' 6 | #sort(reverse=False) - sort ascending 7 | #max() 8 | #min() 9 | #.count - how many occurrences (how many times it shows up) 10 | #.pop - pop last element (remove) 11 | #.remove - remove first occurrence (first time it shows up) 12 | #.clear - clear entire list 13 | #.reverse - change the order 14 | 15 | 16 | list1 = [54, 7, -2, 20, 7] 17 | list2 = ["Arkadiusz", "Jacob"] 18 | 19 | list1.reverse() 20 | 21 | print(list1) 22 | -------------------------------------------------------------------------------- /26. Tuple/tuple.py: -------------------------------------------------------------------------------- 1 | # TUPLE immutable FASTER AND TAKE LESS MEMORY 2 | 3 | tuple = (1, 4, 20, 44) 4 | 5 | print(tuple[0]) 6 | 7 | 8 | -------------------------------------------------------------------------------- /27. Dictionary/dictionary.py: -------------------------------------------------------------------------------- 1 | # dictionary KEY - VALUE 2 | 3 | rooms = {49: 'Arkadiusz Wlodarczyk', 69: 'Wioletta Włodarczyk'} 4 | -------------------------------------------------------------------------------- /28. Sets/set.py: -------------------------------------------------------------------------------- 1 | """ 2 | unique | order | changing specific el. | new elements 3 | LISTS N Y Y Y 4 | TUPLES N Y N N 5 | DICT Y N Y Y 6 | SETS Y N N Y 7 | 8 | SETS have BONUS operations: | & - ^ 9 | """ 10 | 11 | A = {40, -2, 20, 13, 40, 20} 12 | 13 | A.remove(200) 14 | print(A) 15 | -------------------------------------------------------------------------------- /29. Operations on sets/set.py: -------------------------------------------------------------------------------- 1 | """ 2 | unique | order | changing specific el. | new elements 3 | LISTS N Y Y Y 4 | TUPLES N Y N N 5 | DICT Y N Y Y 6 | SETS Y N N Y 7 | 8 | SETS have BONUS operations: | & - ^ 9 | | - UNION 10 | & - intersection 11 | - - difference 12 | ^ - XOR eXlusive OR (removing intersection from union) 13 | """ 14 | 15 | A = {-2, 10, 40, 20} 16 | B = {-2, 10} 17 | 18 | print(B.issubset(A)) 19 | 20 | -------------------------------------------------------------------------------- /30. Nested types/nested-types.py: -------------------------------------------------------------------------------- 1 | # NESTED TYPES UNORDERED 2 | 3 | name = "Arkadiusz" 4 | age = 29 5 | sex = "man" 6 | 7 | name2 = "Jessica" 8 | age2 = 23 9 | sex2 = "woman" 10 | 11 | name3 = "John" 12 | age3 = 32 13 | sex3 = "man" 14 | 15 | 16 | person1 = ['Arkadiusz', 29, 'man'] 17 | person2 = ['Jessica', 23, 'woman'] 18 | person3 = ['John', 33, 'man'] 19 | 20 | guestList = { 21 | ('Arkadiusz', 28, 'man'), 22 | ('Jessica', 22, 'woman'), 23 | ('John', 32, 'man') 24 | } 25 | 26 | guestList2 = { 27 | ('Arkadiusz', 28, 'man'), 28 | ('J', 12, 'woman'), 29 | ('B', 42, 'man') 30 | } 31 | 32 | #guestList[0][1] = 29 33 | guestList3 = guestList & guestList2 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /31. Processing nested types/nested-types.py: -------------------------------------------------------------------------------- 1 | # NESTED TYPES PROCESSING 2 | 3 | 4 | guestList = [ 5 | ('Arkadiusz', 28, 'man'), 6 | ('Jessica', 22, 'woman'), 7 | ('John', 32, 'man') 8 | ] 9 | 10 | for name, age, sex in guestList: 11 | print("Name: ", name) 12 | print("Age: ", age) 13 | print("Sex: ", sex) 14 | print() 15 | -------------------------------------------------------------------------------- /32. Dict in Dict/dicindic.py: -------------------------------------------------------------------------------- 1 | people = { 2 | "IcFDG2bO9AYDF651DoyH": {'name': 'John', 'age': 27, 'sex': 'Male'}, 3 | "KcD9ntE6IRM59vkVta1k": {'name': 'Marie', 'age': 22, 'sex': 'Female'}, 4 | "yDlgcn99xPc19mYXcRmy": {'name': 'Agness', 'age': 25, 'sex': 'Female'}, 5 | "cpQh6GiAbBdGv35NDoTk": {'name': 'Nabeel', 'age': 17, 'sex': 'Male'}, 6 | "12BifzWxCQySKgLhgahC": {'name': 'Jasmin ', 'age': 42, 'sex': 'Female'}, 7 | "QLnmg0pzlLj9x7c7DlLv": {'name': 'Ruby', 'age': 55, 'sex': 'Female'}, 8 | "To47urX0DUznWmOxGZ6H": {'name': 'Lori', 'age': 27, 'sex': 'Male'}, 9 | "KQ4bir3y4tlkbG69I7zq": {'name': 'Marie', 'age': 42, 'sex': 'Female'}, 10 | "94cp4hsyZP2BnCh4D34z": {'name': 'Agness', 'age': 25, 'sex': 'Female'}, 11 | "Vr4wRdkljeEs46Czxo54": {'name': 'Chiara', 'age': 17, 'sex': 'Male'}, 12 | "4WW4F4HiUTP5dBdHatPw": {'name': 'Marie', 'age': 2, 'sex': 'Female'}, 13 | "yuHhrXS1xsSql7kIEnUH": {'name': 'Leila', 'age': 24, 'sex': 'Female'}, 14 | "76XBNSkJn1BIRoX3hB0s": {'name': 'Eric', 'age': 27, 'sex': 'Male'}, 15 | "dMii4kQO1XW4WoiVI7S4": {'name': 'Tobey', 'age': 22, 'sex': 'Female'}, 16 | "DU3Zi0aNj2LLAfujLUWB": {'name': 'Missy', 'age': 25, 'sex': 'Female'} 17 | } 18 | 19 | people2 = [ 20 | {'id': 'IcFDG2bO9AYDF651DoyH', 'name': 'John', 'age': 27, 'sex': 'Male'}, 21 | {'id': 'KcD9ntE6IRM59vkVta1k', 'name': 'Marie', 'age': 22, 'sex': 'Female'}, 22 | {'id': 'yDlgcn99xPc19mYXcRmy', 'name': 'Agness', 'age': 25, 'sex': 'Female'} 23 | ] 24 | 25 | 26 | ratings1 = { 27 | "Arkadiusz": (2,1,2,3,2,3), 28 | "Agness": (4,2,1,3,4) 29 | } 30 | ratings2 = [ 31 | {'name': "Arkadiusz", 'ratings': (2,1,2,3,2,3), 'behaviour': 4}, 32 | {'name': "Agness", 'ratings': (4,2,1,3,4), 'behaviour': 2} 33 | ] 34 | 35 | ratings3 = { 36 | "Arkadiusz": {'ratings': (2,1,2,3,2,3), 'behaviour': 4}, 37 | "Agness:": {'ratings': (4,2,1,3,4), 'behaviour': 2} 38 | } 39 | 40 | 41 | 42 | """ 43 | 44 | ppllist2 = [ 45 | ('John', 27, 'Male'), 46 | ('John3', 22, 'Male'), 47 | ('John2', 11, 'Male') 48 | ] 49 | for name, age, sex in ppllist2: 50 | print(name) 51 | 52 | """ 53 | -------------------------------------------------------------------------------- /33. Extracting values from nested dictionaries/processingdic.py: -------------------------------------------------------------------------------- 1 | people = { 2 | "IcFDG2bO9AYDF651DoyH": {'name': 'John', 'age': 27, 'sex': 'Male'}, 3 | "KcD9ntE6IRM59vkVta1k": {'name': 'Marie', 'age': 22, 'sex': 'Female'}, 4 | "yDlgcn99xPc19mYXcRmy": {'name': 'Agness', 'age': 25, 'sex': 'Female'}, 5 | "cpQh6GiAbBdGv35NDoTk": {'name': 'Nabeel', 'age': 17, 'sex': 'Male'}, 6 | "12BifzWxCQySKgLhgahC": {'name': 'Jasmin ', 'age': 42, 'sex': 'Female'}, 7 | "QLnmg0pzlLj9x7c7DlLv": {'name': 'Ruby', 'age': 55, 'sex': 'Female'}, 8 | "To47urX0DUznWmOxGZ6H": {'name': 'Lori', 'age': 27, 'sex': 'Male'}, 9 | "KQ4bir3y4tlkbG69I7zq": {'name': 'Marie', 'age': 42, 'sex': 'Female'}, 10 | "94cp4hsyZP2BnCh4D34z": {'name': 'Agness', 'age': 25, 'sex': 'Female'}, 11 | "Vr4wRdkljeEs46Czxo54": {'name': 'Chiara', 'age': 17, 'sex': 'Male'}, 12 | } 13 | 14 | 15 | 16 | people2 = [ 17 | {'id': 'IcFDG2bO9AYDF651DoyH', 'name': 'John', 'age': 27, 'sex': 'Male'}, 18 | {'id': 'KcD9ntE6IRM59vkVta1k', 'name': 'Marie', 'age': 22, 'sex': 'Female'}, 19 | {'id': 'yDlgcn99xPc19mYXcRmy', 'name': 'Agness', 'age': 25, 'sex': 'Female'} 20 | ] 21 | 22 | people3 = ["Arkadiusz", 23 | "Wiola", 24 | "Kuba" 25 | ] 26 | 27 | 28 | 29 | ratings1 = { 30 | "Arkadiusz": (2,1,2,3,2,3), 31 | "Agness": (4,2,1,3,4) 32 | } 33 | 34 | 35 | 36 | 37 | """ 38 | ppllist = [ 39 | ('John', 27, 'Male'), 40 | ('John3', 22, 'Male'), 41 | ('John2', 11, 'Male') 42 | ] 43 | 44 | """ 45 | 46 | 47 | 48 | """ 49 | ratings2 = [ 50 | {'name': "Arkadiusz", 'ratings': (2,1,2,3,2,3), 'behaviour': 4}, 51 | {'name': "Agness", 'ratings': (4,2,1,3,4), 'behaviour': 2} 52 | ] 53 | 54 | ratings3 = { 55 | "Arkadiusz": {'ratings': (2,1,2,3,2,3), 'behaviour': 4}, 56 | "Agness:": {'ratings': (4,2,1,3,4), 'behaviour': 2} 57 | } 58 | """ 59 | -------------------------------------------------------------------------------- /34. Exercise - dictionary of definitions/dicexercise.py: -------------------------------------------------------------------------------- 1 | """ 2 | Write a program that will allow the user to: 3 | 1) Add new definitions 4 | 2) Search existing definitions 5 | 3) Delete the definition that he has chosen 6 | TAB 7 | """ 8 | 9 | dictionary = {} 10 | 11 | while(True): 12 | print("1: Add definition") 13 | print("2: Search for definition") 14 | print("3: Remove definition") 15 | print("4: End") 16 | 17 | choice = input("What do you want to do? ") 18 | 19 | if (choice == "1"): 20 | key = input("Enter the word (key) to define: ") 21 | definition = input("Enter definition: ") 22 | dictionary[key] = definition 23 | print("Definition added successfully") 24 | elif (choice == "2"): 25 | key = input("What are you searching for? ") 26 | if key in dictionary: 27 | print(dictionary[key]) 28 | else: 29 | print("Definition has not been found: ", key) 30 | elif (choice == "3"): 31 | key = input("What definition do you want to remove? ") 32 | if key in dictionary: 33 | del dictionary[key] 34 | print("Definition", key," removed successfully") 35 | else: 36 | print("Definition has not been found: ", key) 37 | elif (choice == "4"): 38 | print("Bye then!") 39 | break 40 | -------------------------------------------------------------------------------- /35. List comprehension/list-comprehension.py: -------------------------------------------------------------------------------- 1 | """ LIST comprehensions (expressions/formulas)""" 2 | 3 | numbers = [1, 2, 3, 4, 5, 6] 4 | 5 | poweredNumbers = [] 6 | for element in numbers: 7 | poweredNumbers.append(element**2) 8 | 9 | evenNumbers = [] 10 | for element in numbers: 11 | if (element % 2 == 0): 12 | evenNumbers.append(element) 13 | 14 | 15 | poweredNumbers2 = [element**2 16 | for element in range(51) 17 | ] 18 | 19 | evenNumbers2 = [element 20 | for element in numbers 21 | if (element % 2 == 0) 22 | ] 23 | 24 | """ 25 | [what_to_do_on_element | for element in old_list | condition_based_on_element] 26 | 27 | element/item/entry 28 | """ 29 | -------------------------------------------------------------------------------- /36. Generator expressions/generators.py: -------------------------------------------------------------------------------- 1 | import sys 2 | """generator expressions""" 3 | 4 | evenNumbers = [element 5 | for element in range(4401) 6 | if (element % 2 == 0) 7 | ] 8 | 9 | evenNumbersGenerator = (element 10 | for element in range(4401) 11 | if (element % 2 == 0) 12 | ) 13 | 14 | 15 | print(sum(evenNumbersGenerator)) 16 | """ 17 | print(evenNumbers) 18 | print(evenNumbersGenerator) 19 | 20 | for number in evenNumbersGenerator: 21 | print(number) 22 | 23 | print(sys.getsizeof(evenNumbers)) 24 | print(sys.getsizeof(evenNumbersGenerator)) 25 | """ 26 | -------------------------------------------------------------------------------- /37. Dictionary comprehension/dictionarycomprehension.py: -------------------------------------------------------------------------------- 1 | """ 2 | dictionary comprehensions(expressions/formula) 3 | """ 4 | 5 | names = {"Arkadiusz", "Wioletta", "Karol", "Bartłomiej", "Jakub", "Ania"} 6 | 7 | numbers = [1, 2, 3, 4, 5, 6] 8 | 9 | celsius = {'t1': -20, 't2': -15, 't3': 0, 't4': 12, 't5': 24} 10 | 11 | namesLength = { 12 | name : len(name) 13 | for name in names 14 | if name.startswith("A") 15 | } 16 | 17 | multipliedNumbers = { 18 | number: number*number 19 | for number in range(1,500) 20 | } 21 | 22 | fahrenheit = { 23 | key: celsius * 1.8 + 32 24 | for key, celsius in celsius.items() 25 | if celsius > -10 26 | if celsius < 20 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /38. Set comprehension/setcomprehensions.py: -------------------------------------------------------------------------------- 1 | """ 2 | set comprehensions (expressions) 3 | """ 4 | 5 | names = {"arkadiusz", "Agness", "carol", "james", "Eric", "Susane"} 6 | 7 | names = { 8 | name.capitalize() 9 | for name in names 10 | } 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /39. Exercise with divisible numbers/practise.py: -------------------------------------------------------------------------------- 1 | """ 2 | Find numbers from 2 to 470, that are: 3 | - divisible by 7, but are not divisible by 5 4 | 5 | What will you use? 6 | 1) generator expression 7 | 2) list comprehension 8 | 3) set comprehension 9 | 4) dictionary comprehension 10 | 11 | Think for a second and make notes: 12 | "is the answer to above question always the same?" 13 | 14 | range(2, 471) 15 | 16 | 7 17 | 14 18 | 21 19 | 28 20 | 35 21 | 42 22 | 49 23 | 56 24 | 25 | 5 26 | 10 27 | 15 28 | 20 29 | 25 30 | 30 31 | 35 32 | 40 33 | 45 34 | 50 35 | 55 36 | 37 | 7 % 7 == 0 38 | 14 % 7 == 0 39 | 21 % 7 == 0 40 | 28 % 7 == 0 41 | 35 % 7 == 0 42 | 43 | 44 | 35 % 5 == 0 45 | 14 % 5 == 4 46 | 47 | """ 48 | numbers = { 49 | number 50 | for number in range(2, 471) 51 | if (number % 7 == 0) 52 | if (number % 5 != 0) 53 | } 54 | 55 | print(numbers) 56 | 57 | 58 | -------------------------------------------------------------------------------- /40. How to create a function/functions.py: -------------------------------------------------------------------------------- 1 | """ 2 | Function - is a block of code that you can access any time 3 | to get the result you want 4 | 5 | 6 | def name_of_function(): 7 | instruction1 8 | instruction2 9 | instruction3 10 | 11 | definition 12 | parameter 13 | """ 14 | 15 | def welcome_message(name): 16 | print("Hello",name,"welcome in my program!") 17 | 18 | 19 | names = ["Arkadiusz", "Agness", "Denis"] 20 | 21 | for name in names: 22 | print("Hello",name,"welcome in my program!") 23 | 24 | 25 | -------------------------------------------------------------------------------- /41. Passing more than one argument/many-parameters.py: -------------------------------------------------------------------------------- 1 | """ function with multiple parameters 2 | area of the rectangle 3 | 4 | side1 and side2 5 | 6 | """ 7 | 8 | def area_rectangle(side1, side2): 9 | print(side1 * side2) 10 | 11 | area_rectangle(2) 12 | 13 | 14 | -------------------------------------------------------------------------------- /42. Return value/EXERCISE - Add functions to existing code.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/42. Return value/EXERCISE - Add functions to existing code.docx -------------------------------------------------------------------------------- /42. Return value/EXERCISE - Count the area of figures.txt: -------------------------------------------------------------------------------- 1 | EXERCISE: Count the area of figures 2 | Create a menu for the user from which he can choose to count the area of figures: 3 | 4 | square 5 | 6 | rectangle 7 | 8 | triangle 9 | 10 | trapeze 11 | 12 | Remember to use functions. -------------------------------------------------------------------------------- /42. Return value/Return and invoke.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/42. Return value/Return and invoke.docx -------------------------------------------------------------------------------- /42. Return value/return.py: -------------------------------------------------------------------------------- 1 | """ return as the name suggests  2 | returns to the place where the function was invoked. 3 | 4 | None logical False 5 | """ 6 | 7 | def area_rectangle(side1, side2): 8 | return side1 * side2 9 | 10 | 11 | 12 | areaRectangleA = area_rectangle(4, 6) 13 | areaRectangleB = area_rectangle(2, 24) 14 | 15 | #print("The area of rectangle is equal to: ", 5 * areaRectangleA) 16 | #print("The area of rectangle is equal to: ", 7 * areaRectangleB) 17 | 18 | 19 | def divide(a, b): 20 | if (b == 0): 21 | return 22 | 23 | return a / b 24 | 25 | x = divide(20,5) 26 | if(x): 27 | print("The numbers were divided properly, the result is equal to:", x) 28 | else: 29 | print("Division by zero") 30 | -------------------------------------------------------------------------------- /43. Your own module imported/SOURCE CODE - YOUR OWN MODULES.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/43. Your own module imported/SOURCE CODE - YOUR OWN MODULES.zip -------------------------------------------------------------------------------- /43. Your own module imported/__pycache__/figures.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/43. Your own module imported/__pycache__/figures.cpython-37.pyc -------------------------------------------------------------------------------- /43. Your own module imported/figures.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def area_of_square(a): 4 | return a * a 5 | 6 | def area_of_rectangle(a, b): 7 | return a * b 8 | 9 | def area_of_circle(r): 10 | return math.pi * r ** 2 11 | 12 | def area_of_triangle(a, h): 13 | return 0.5 * a * h 14 | 15 | def area_of_trapeze(a, b, h): 16 | return (a + b) / 2 * h 17 | 18 | 19 | -------------------------------------------------------------------------------- /43. Your own module imported/main_program.py: -------------------------------------------------------------------------------- 1 | import figures 2 | 3 | choose = input("""What figure area you want to measure? 4 | 1. Square 5 | 2. Rectangle 6 | 3. Circle 7 | 4. Triangle 8 | 5. Trapeze 9 | """) 10 | 11 | if (choose == '1'): 12 | a = float(input("Enter the size of square side: ")) 13 | print("The area of square is equal to:", figures.area_of_square(a)) 14 | -------------------------------------------------------------------------------- /43.1. enum/__pycache__/figures.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/43.1. enum/__pycache__/figures.cpython-37.pyc -------------------------------------------------------------------------------- /43.1. enum/figures.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def area_of_square(a): 4 | return a * a 5 | 6 | def area_of_rectangle(a, b): 7 | return a * b 8 | 9 | def area_of_circle(r): 10 | return math.pi * r ** 2 11 | 12 | def area_of_triangle(a, h): 13 | return 0.5 * a * h 14 | 15 | def area_of_trapeze(a, b, h): 16 | return (a + b) / 2 * h 17 | 18 | 19 | -------------------------------------------------------------------------------- /43.1. enum/main_program.py: -------------------------------------------------------------------------------- 1 | import figures 2 | 3 | #enum - enumeration - list of elements that are enumerated (numbered) starting from 1 4 | 5 | from enum import IntEnum 6 | 7 | #Menu_Figures = IntEnum('Menu_Figures', {'Square':44, 'Rectangle':12, 'Circle':42, 'Triangle':5, 'Trapeze':2}) 8 | Menu_Figures = IntEnum('Menu_Figures', ['Square', 'Rectangle', 'Circle', 'Triangle', 'Trapeze']) 9 | print(list(Menu_Figures)) 10 | 11 | choose = int(input("""What figure area you want to measure? 12 | 1. Square 13 | 2. Rectangle 14 | 3. Circle 15 | 4. Triangle 16 | 5. Trapeze 17 | """)) 18 | 19 | if (choose == Menu_Figures.Square): 20 | a = float(input("Enter the size of square side: ")) 21 | print("The area of square is equal to:", figures.area_of_square(a)) 22 | elif (choose == Menu_Figures.Rectangle): 23 | a = float(input("Enter the size of 1-st side of rectangle ")) 24 | b = float(input("Enter the size of 2-nd side of rectangle: ")) 25 | print("The area of rectangle is equal to:", figures.area_of_rectangle(a, b)) 26 | elif (choose == Menu_Figures.Circle): 27 | r = float(input("Enter the radius of circle ")) 28 | print("The area of circle is equal to:", figures.area_of_circle(r)) 29 | elif (choose == Menu_Figures.Triangle): 30 | a = float(input("Enter the side of triangle: ")) 31 | h = float(input("Enter the height of triangle: ")) 32 | print("The area of triangle is equal to:", figures.area_of_triangle(a, h)) 33 | elif (choose == Menu_Figures.Trapeze): 34 | a = float(input("Enter the size of 1-st side of trapeze ")) 35 | b = float(input("Enter the size of 2-nd side of trapeze: ")) 36 | h = float(input("Enter the height of trapeze: ")) 37 | print("The area of trapeze is equal to:", figuryfiguresarea_of_trapeze(a, b, h)) 38 | -------------------------------------------------------------------------------- /44. EXERCISE Arithmetic Sequence/arithmeticsequence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Write program, that will count the sum of all numbers from 1 to 3 | number that was entered by user. 4 | 5 | 1,2,3,4,5,... 100 6 | 7 | (1 + 100) / 2 * 100 8 | 9 | For 5: 10 | 1+2+3+4+5 11 | the result is gonna be: 12 | 15 13 | 14 | 15 | (1 + 5) / 2 * 5 = 15 16 | 17 | range(1, 6) 18 | 1,2,3,4,5 19 | """ 20 | 21 | def sum_up_to(end): 22 | sum = 0 # 15 23 | 24 | for number in range(1, end+1): #number = 5 25 | sum = sum + number 26 | 27 | return sum 28 | 29 | def sum_up_to2(end): 30 | return sum([number for number in range(1, end+1)]) 31 | def sum_up_to3(end): 32 | return sum({number for number in range(1, end+1)}) 33 | def sum_up_to4(end): 34 | return sum((number for number in range(1, end+1))) 35 | def sum_up_to5(end): 36 | return (1 + end) / 2 * end 37 | 38 | 39 | 40 | print(sum_up_to(1255)) 41 | print(sum_up_to2(1255)) 42 | print(sum_up_to3(1255)) 43 | print(sum_up_to4(1255)) 44 | print(sum_up_to5(1255)) 45 | -------------------------------------------------------------------------------- /45. Measuring performance of code/Python-for-Beginners-Learn-Python-from-Scratch-master - Shortcut.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/45. Measuring performance of code/Python-for-Beginners-Learn-Python-from-Scratch-master - Shortcut.lnk -------------------------------------------------------------------------------- /45. Measuring performance of code/arithmeticsequence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Measuring the performance of code 3 | """ 4 | 5 | import time 6 | 7 | def sum_up_to(end): 8 | sum = 0 9 | 10 | for number in range(1, end+1): 11 | sum = sum + number 12 | 13 | return sum 14 | 15 | def sum_up_to2(end): 16 | return sum([number for number in range(1, end+1)]) 17 | def sum_up_to3(end): 18 | return sum({number for number in range(1, end+1)}) 19 | def sum_up_to4(end): 20 | return sum((number for number in range(1, end+1))) 21 | def sum_up_to5(end): 22 | return (1 + end) / 2 * end 23 | 24 | 25 | start = time.perf_counter() 26 | print(sum_up_to(325)) 27 | end = time.perf_counter() 28 | print(end-start) 29 | 30 | start = time.perf_counter() 31 | print(sum_up_to2(325)) 32 | end = time.perf_counter() 33 | print(end-start) 34 | 35 | start = time.perf_counter() 36 | print(sum_up_to3(325)) 37 | end = time.perf_counter() 38 | print(end-start) 39 | 40 | start = time.perf_counter() 41 | print(sum_up_to4(325)) 42 | end = time.perf_counter() 43 | print(end-start) 44 | 45 | start = time.perf_counter() 46 | print(sum_up_to5(325)) 47 | end = time.perf_counter() 48 | print(end-start) 49 | -------------------------------------------------------------------------------- /46. Function as function argument/arithmeticsequence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Measuring the performance of code 3 | """ 4 | 5 | import time 6 | 7 | def sum_up_to(end): 8 | sum = 0 9 | 10 | for number in range(1, end+1): 11 | sum = sum + number 12 | 13 | return sum 14 | 15 | def sum_up_to2(end): 16 | return sum([number for number in range(1, end+1)]) 17 | def sum_up_to3(end): 18 | return sum({number for number in range(1, end+1)}) 19 | def sum_up_to4(end): 20 | return sum((number for number in range(1, end+1))) 21 | def sum_up_to5(end): 22 | return (1 + end) / 2 * end 23 | 24 | 25 | #function_performance(sum_up_to, 325) 26 | 27 | def show_message(message): 28 | print(message) 29 | 30 | def function_performance(x, arg): 31 | start = time.perf_counter() 32 | x(arg) 33 | end = time.perf_counter() 34 | return end-start 35 | 36 | print(function_performance(sum_up_to, 500000)) 37 | print(function_performance(sum_up_to2, 500000)) 38 | print(function_performance(sum_up_to3, 500000)) 39 | print(function_performance(sum_up_to4, 500000)) 40 | print(function_performance(sum_up_to5, 500000)) 41 | 42 | 43 | """ 44 | start = time.perf_counter() 45 | print(sum_up_to(325)) 46 | end = time.perf_counter() 47 | print(end-start) 48 | 49 | start = time.perf_counter() 50 | print(sum_up_to2(325)) 51 | end = time.perf_counter() 52 | print(end-start) 53 | 54 | start = time.perf_counter() 55 | print(sum_up_to3(325)) 56 | end = time.perf_counter() 57 | print(end-start) 58 | 59 | start = time.perf_counter() 60 | print(sum_up_to4(325)) 61 | end = time.perf_counter() 62 | print(end-start) 63 | 64 | start = time.perf_counter() 65 | print(sum_up_to5(325)) 66 | end = time.perf_counter() 67 | print(end-start) 68 | """ 69 | -------------------------------------------------------------------------------- /47. default arguments/defaultarguments.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def sum_up_to(end): 4 | sum = 0 5 | 6 | for number in range(1, end+1): 7 | sum = sum + number 8 | 9 | return sum 10 | 11 | def sum_up_to2(end): 12 | return sum([number for number in range(1, end+1)]) 13 | def sum_up_to3(end): 14 | return sum({number for number in range(1, end+1)}) 15 | def sum_up_to4(end): 16 | return sum((number for number in range(1, end+1))) 17 | def sum_up_to5(end): 18 | return (1 + end) / 2 * end 19 | 20 | 21 | #function_performance(sum_up_to, 325) 22 | 23 | def show_message(message): 24 | print(message) 25 | 26 | def function_performance(x, arg, how_many_times = 1): 27 | sum = 0 28 | 29 | for i in range(0, how_many_times): 30 | start = time.perf_counter() 31 | x(arg) 32 | end = time.perf_counter() 33 | how_long = end-start 34 | sum = sum + how_long 35 | 36 | return sum 37 | 38 | print(function_performance(sum_up_to, 500000, 25)) 39 | print(function_performance(sum_up_to2, 500000)) 40 | print(function_performance(sum_up_to3, 500000)) 41 | print(function_performance(sum_up_to4, 500000)) 42 | print(function_performance(sum_up_to5, 500000)) 43 | 44 | 45 | """ 46 | start = time.perf_counter() 47 | print(sum_up_to(325)) 48 | end = time.perf_counter() 49 | print(end-start) 50 | 51 | start = time.perf_counter() 52 | print(sum_up_to2(325)) 53 | end = time.perf_counter() 54 | print(end-start) 55 | 56 | start = time.perf_counter() 57 | print(sum_up_to3(325)) 58 | end = time.perf_counter() 59 | print(end-start) 60 | 61 | start = time.perf_counter() 62 | print(sum_up_to4(325)) 63 | end = time.perf_counter() 64 | print(end-start) 65 | 66 | start = time.perf_counter() 67 | print(sum_up_to5(325)) 68 | end = time.perf_counter() 69 | print(end-start) 70 | """ 71 | -------------------------------------------------------------------------------- /47. default arguments/defaultarguments2.py: -------------------------------------------------------------------------------- 1 | "default - standard arguments" 2 | 3 | def increase(x, amount = 1): 4 | return x + amount 5 | -------------------------------------------------------------------------------- /48. named and unnamed arguments/namedandunnamedarguments.py: -------------------------------------------------------------------------------- 1 | """ 2 | Named(keyword) and unnamed (positional) arguments 3 | 4 | keyword - key=value 5 | positional - where the sequence (position) matters 6 | """ 7 | 8 | def greet(name, message="Hello", seperator=" "): 9 | print(message, name, sep=seperator) 10 | 11 | #print("sample", "sample2", "sample3", ',') 12 | 13 | greet("Arkadiusz", seperator="\n") 14 | -------------------------------------------------------------------------------- /49. EXERCISE - checking if value is in container/exercise.py: -------------------------------------------------------------------------------- 1 | """ 2 | EXERCISE TIME :-) 3 | 4 | Write a function that will check if the container contains 5 | searched value. 6 | 7 | If the value is found return True 8 | If the value is not found return False 9 | 10 | CHECK PERFORMANCE of your function on set and list containing 11 | over 1000 values. 12 | 13 | """ 14 | 15 | import time 16 | 17 | def function_performance(func, arg, how_many_times = 1): 18 | sum = 0 19 | 20 | for i in range(0, how_many_times): 21 | start = time.perf_counter() 22 | func(arg) 23 | end = time.perf_counter() 24 | sum = sum + (end-start) 25 | 26 | return sum 27 | 28 | setContainer = {i for i in range(10000)} 29 | listContainer = [i for i in range(10000)] 30 | 31 | 32 | def is_value_in(what_value): 33 | if what_value in setContainer: 34 | return True 35 | else: 36 | return False 37 | 38 | print(function_performance(is_value_in, 1500, 50000)) 39 | -------------------------------------------------------------------------------- /50. Variable Length Argument/variable-length-argument.py: -------------------------------------------------------------------------------- 1 | """ 2 | Variable length argument 3 | 4 | How to send unknown amount of arguments? 5 | 6 | """ 7 | 8 | import time 9 | 10 | def function_performance(func, how_many_times = 1, **arg): 11 | sum = 0 12 | 13 | 14 | for i in range(0, how_many_times): 15 | start = time.perf_counter() 16 | func(**arg) 17 | end = time.perf_counter() 18 | sum = sum + (end-start) 19 | 20 | return sum 21 | 22 | setContainer = {i for i in range(100)} 23 | listContainer = [i for i in range(100)] 24 | 25 | def is_value_in(what_value, container): 26 | if what_value in container: 27 | return True 28 | else: 29 | return False 30 | 31 | 32 | print(function_performance(is_value_in, 50000, what_value=1500, 33 | container=setContainer )) 34 | print(function_performance(is_value_in, 50000, what_value=1500, 35 | container=listContainer )) 36 | 37 | """positional arguments(unnamed) BEFORE named arguments (keyword) """ 38 | 39 | #count(2,4,1,2,4,12,5125,125,125) 40 | -------------------------------------------------------------------------------- /51. Local vs global scope/localvsglobalscope.py: -------------------------------------------------------------------------------- 1 | def add(x): 2 | x = 50 3 | print(x) 4 | 5 | """ LOCAL VARIABLES are temporary and their life is between the start 6 | and end of the BODY of function 7 | 8 | WHENEVER you create a variable INSIDE a function or as parameter it is INSTANTLY 9 | a LOCA variable 10 | """ 11 | 12 | x = 1 13 | 14 | add(x) 15 | 16 | print(x) 17 | 18 | -------------------------------------------------------------------------------- /52. Mutable vs immutable objects/mutablevsimmutableobjects.py: -------------------------------------------------------------------------------- 1 | """ 2 | object is a variable with MORE features than just showing value 3 | You can invoke a function ON object 4 | object can have many different values 5 | 6 | immutable - unchangable (after sending as argument) 7 | mutable - changable 8 | 9 | immutable object: bool, int, float, tuple, str 10 | 11 | = - means CHANGING the address. Since now the object points to DIFFENT place 12 | 13 | METHOD 14 | """ 15 | 16 | x = 4 17 | #y = x 18 | #y = 20 19 | #print(id(x)) 20 | 21 | #listSample2 = listSample1 22 | 23 | #listSample1.append(4) 24 | 25 | def add(x, amount=1): 26 | print(id(x)) 27 | x = x + amount 28 | print(id(x)) 29 | 30 | #add(x) 31 | 32 | g = 20 33 | h = 20 34 | 35 | 36 | listSample1 = [2, 42, 125] 37 | 38 | print(id(listSample1)) 39 | 40 | def append_element_to_list(WHATAVER, element): 41 | print(id(WHATAVER)) 42 | a = [124, 124, 52, 1] # 43 | WHATAVER = a 44 | print(id(WHATAVER)) 45 | WHATAVER.append(4) 46 | 47 | append_element_to_list(listSample1, 2000) 48 | 49 | print(listSample1) 50 | -------------------------------------------------------------------------------- /52.5 shallow vs deep copy/shallowvsdeepcopy.py: -------------------------------------------------------------------------------- 1 | """ 2 | copy - shallow (of little depth) 3 | deepcopy - copy of each every mutable element inside of object 4 | 5 | mutable 6 | immutable 7 | """ 8 | import copy 9 | 10 | def evil_function(toBeDestroyedList): 11 | print(id(toBeDestroyedList[0])) 12 | toBeDestroyedList[0] = 444 13 | print(id(toBeDestroyedList[0])) 14 | print(toBeDestroyedList) 15 | 16 | 17 | #myList = [[1, 4], [2, 1], [52, 3]] 18 | myList = [1, 4, 2, 1, 52, 3] 19 | 20 | print(id(myList[0])) 21 | evil_function(myList.copy()) 22 | print(id(myList[0])) 23 | print(myList) 24 | 25 | 26 | a = 4 27 | b = 4 28 | -------------------------------------------------------------------------------- /53. lambda, anonymous functions/lambdaanonymousfunctions.py: -------------------------------------------------------------------------------- 1 | """ 2 | lambda - anonymous functions (functions without names) 3 | 4 | """ 5 | def multiply(x): 6 | return x * 2 7 | 8 | 9 | def function_to_filter(x): 10 | if (x % 2) == 0: 11 | return x 12 | 13 | print((lambda x: x * 2)(4)) 14 | 15 | 16 | my_list = [2, 24, 21, 7, 20] 17 | 18 | print(list(filter(lambda x: x % 2 == 0, my_list))) 19 | print(list(map(lambda x: x * 2, my_list))) 20 | 21 | my_list_filtered = [x for x in my_list if (x % 2) == 0] 22 | -------------------------------------------------------------------------------- /53.1. any fuction exercise/EXERICSE - Enumarate() tasks and show them to the user.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/53.1. any fuction exercise/EXERICSE - Enumarate() tasks and show them to the user.docx -------------------------------------------------------------------------------- /53.1. any fuction exercise/Use the all() function to determine if a person has a required set of skills.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/53.1. any fuction exercise/Use the all() function to determine if a person has a required set of skills.docx -------------------------------------------------------------------------------- /53.1. any fuction exercise/test.py: -------------------------------------------------------------------------------- 1 | """ 2 | Use the any() function to 3 | determine whether the submitted list contains even numbers 4 | 5 | all() 6 | """ 7 | numbers1 = [1, 3, 5, 8] 8 | numbers2 = [1, 3, 5, 7] 9 | 10 | def any_even(list): 11 | return any([nr % 2 == 0 for nr in list]) 12 | 13 | def all_even(list): 14 | return all([nr % 2 == 0 for nr in list]) 15 | 16 | 17 | print(any_even(numbers1)) # True 18 | print(any_even(numbers2)) # False 19 | 20 | if (any_even(numbers1)): 21 | print("one of the number is even") 22 | else: 23 | print("none is even") 24 | 25 | if (any_even(numbers2)): 26 | print("one of the number is even") 27 | else: 28 | print("none is even") 29 | 30 | # any - IF ANY value is True 31 | 32 | 33 | john = { 34 | 'name': 'John Doe', 35 | 'age': 30, 36 | 'skills': ['Python', 'JavaScript', 'C++'] 37 | } 38 | 39 | jane = { 40 | 'name': 'Jane Smith', 41 | 'age': 25, 42 | 'skills': ['Python', 'Java'] 43 | } 44 | -------------------------------------------------------------------------------- /54. random numbers/drawingrandomnumbers.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Drawing RANDOM numbers 4 | 5 | random numbers 6 | 7 | random() 0 <= x < 1 lub [0,1) 8 | 9 | uniform(2.5, 10.0) 2.5 <= x < 10.0 lub [2.5, 10) 10 | randrange(10) from (0,1,2,3,4,5,6,7,8,9) 11 | randrange(0, 15, 2) even nr from (0,2,4..14) 12 | 13 | randint(0, 4) [0,4] 14 | 15 | """ 16 | 17 | import random 18 | 19 | x = 0 20 | """ 21 | while x < 100: 22 | x = x + 1 23 | print(random.uniform(0, 100)) 24 | """ 25 | weaponChanceToHitPercentage = 50 26 | 27 | def will_weapon_hit(weaponChanceToHitPercentage): 28 | chanceToHit = random.uniform(0, 100) 29 | if (weaponChanceToHitPercentage > chanceToHit): 30 | return "hit" 31 | else: 32 | return "not hit" 33 | 34 | hitList = [] 35 | 36 | while x < 1000: 37 | x = x + 1 38 | hitList.append(random.randint(0, 10)) 39 | 40 | from collections import Counter 41 | print(Counter(hitList)) 42 | -------------------------------------------------------------------------------- /55. choice/choice.py: -------------------------------------------------------------------------------- 1 | """ 2 | choice - chooses random element from the provided list, 3 | the probability of getting each element is equal 4 | 5 | Python 3.6+: 6 | choices - return list of random element/s from provided list 7 | allows to: 8 | - set probability using weighted average 9 | - set how many times we want to draw from provided list and 10 | return all results inside a single list 11 | 12 | """ 13 | 14 | import random 15 | 16 | movieList = ["Title 1", "Title 2", "Title 3", "Title 4"] 17 | 18 | randomEvent = ["death", "win", "failure", "gold lost", "hp lost", "random item gained"] 19 | 20 | chestReward = ["green", "orange", "purple", "legendary (gold)"] 21 | 22 | from collections import Counter 23 | 24 | print(Counter(random.choices(chestReward, [0.80, 0.15, 0.04, 0.01], k = 100))) 25 | -------------------------------------------------------------------------------- /56. shuffle/shuffle-en.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/56. shuffle/shuffle-en.mp4 -------------------------------------------------------------------------------- /56. shuffle/shuffle.py: -------------------------------------------------------------------------------- 1 | """ 2 | shuffle - randomizes and changes the place of all elements inside entire list 3 | 4 | """ 5 | 6 | import random 7 | 8 | cardList = ["9", "9", "9", "9", 9 | "10", "10", "10", "10", 10 | "Jack", "Jack", "Jack", "Jack", 11 | "Queen", "Queen", "Queen", "Queen", 12 | "King", "King", "King", "King", 13 | "Ace", "Ace", "Ace", "Ace" 14 | "Joker", "Joker"] 15 | 16 | 17 | random.shuffle(cardList) 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /57. sample/sample.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Write a function that will simulate how lottery works: 4 | return 6 UNIQUE numbers from a set of 49 numbers 5 | 6 | SAMPLE - returns a LIST with randomly chosen elements from another list 7 | sample function makes SURE that it won't 8 | choose the same element TWICE 9 | 10 | """ 11 | 12 | import random 13 | 14 | cardList = ["9", "9", "9", "9", 15 | "10", "10", "10", "10", 16 | "Jack", "Jack", "Jack", "Jack", 17 | "Queen", "Queen", "Queen", "Queen", 18 | "King", "King", "King", "King", 19 | "Ace", "Ace", "Ace", "Ace", 20 | "Joker", "Joker"] 21 | 22 | 23 | random.shuffle(cardList) 24 | 25 | print(cardList) 26 | """ 27 | player1Cards = random.sample(cardList, 5) 28 | player2Cards = random.sample(cardList, 5) 29 | """ 30 | player1Cards = [] 31 | player1Cards.append(cardList.pop()) 32 | player1Cards.append(cardList.pop()) 33 | player1Cards.append(cardList.pop()) 34 | """ 35 | [0,1,2,3,... ,49] 36 | def choose_random_numbers(amount, total_amount): 37 | return random.sample(range(total_amount + 1), amount) 38 | 39 | 40 | print(choose_random_numbers(6, 49)) 41 | print(choose_random_numbers(2, 30)) 42 | print(choose_random_numbers(30, 50)) 43 | """ 44 | -------------------------------------------------------------------------------- /58. Game drawing chests with gold/gamedrawingchests.py: -------------------------------------------------------------------------------- 1 | """ 2 | Write a game where the player can move 5 times in 3 | ONE direction 4 | 5 | The player has a chance to find a chest(40%) or nothing(60%) 6 | 7 | The chests have different colours and different rewards based on colours 8 | 9 | The chance to get 10 | green - 75% 11 | orange - 20% 12 | purple - 4% 13 | gold (legendary) - 1% 14 | 15 | Gold is a thing that can reward a player that opens the chest: 16 | green - 1000 17 | orange - 4000 18 | purple - 9000 19 | gold (legendary) - 16000 20 | 21 | 1 1 *1 (0 +1) * (0 + 1) = 1 22 | 4 2*2 1 (1 + 1) * (1 + 1) = 4 * 1000 23 | 9 3* 3 2 24 | 16 4 * 4 3 25 | 26 | Make sure to write: 27 | 1) clean code 28 | 2) make self-descriptive variables 29 | 30 | """ 31 | import random 32 | from enum import Enum 33 | 34 | Event = Enum('Event', ['Chest', 'Nothing']) 35 | 36 | eventDictionary = { 37 | Event.Chest: 0.8, 38 | Event.Nothing: 0.2 39 | } 40 | eventList = tuple(eventDictionary.keys()) 41 | eventProbability = tuple(eventDictionary.values()) 42 | 43 | Colours = Enum('Colours', {"Green": "green", 44 | "Orange": "orange", 45 | "Purple": "purple", 46 | "Gold": "LEGENDARY" 47 | }) 48 | 49 | chestColoursDictionary = { 50 | Colours.Green : 0.75, 51 | Colours.Orange : 0.2, 52 | Colours.Purple : 0.04, 53 | Colours.Gold : 0.01 54 | } 55 | chestColourList = tuple(chestColoursDictionary.keys()) 56 | 57 | chestColourProbability = tuple(chestColoursDictionary.values()) 58 | 59 | rewardsForChests = { 60 | chestColourList[reward]: (reward + 1) * (reward + 1) * 1000 61 | for reward in range(4) 62 | } 63 | 64 | gameLength = 5 65 | goldAcquired = 0 66 | while gameLength > 0: 67 | playerAnswer = input("Do you want to move forward?") 68 | if (playerAnswer == "yes"): 69 | print("Great, let's see what you got...") 70 | drawnEvent = random.choices(eventList, eventProbability)[0] 71 | if(drawnEvent == Event.Chest): 72 | print("You've drawn a CHEST") 73 | drawnColour = random.choices(chestColourList, chestColourProbability)[0] 74 | print("The chest color is", drawnColour.value) 75 | playerReward = rewardsForChests[drawnColour] 76 | goldAcquired = goldAcquired + playerReward 77 | elif(drawnEvent == Event.Nothing): 78 | print("You've drawn nothing, you are so unlucky!") 79 | 80 | else: 81 | print("You can go just straight man, nothing else, this game is dumb") 82 | continue 83 | 84 | gameLength = gameLength - 1 85 | 86 | print("Congratulation, you have acquired:", goldAcquired) 87 | 88 | 89 | -------------------------------------------------------------------------------- /59. GAME drawing approximate values to certain value/drawingapproximatevalues.py: -------------------------------------------------------------------------------- 1 | """ 2 | Write a game where the player can move 5 times in 3 | ONE direction 4 | 5 | The player has a chance to find a chest(40%) or nothing(60%) 6 | 7 | The chests have different colours and different rewards based on colours 8 | 9 | The chance to get 10 | green - 75% 11 | orange - 20% 12 | purple - 4% 13 | gold (legendary) - 1% 14 | 15 | Gold is a thing that can reward a player that opens the chest: 16 | green - 1000 17 | orange - 4000 18 | purple - 9000 19 | gold (legendary) - 16000 20 | 21 | 1000: 900 1100 randint(900, 1100) 22 | 4000: 3600 4400 randint(3600, 4400) 23 | 24 | 25 | 1 1 *1 (0 +1) * (0 + 1) = 1 26 | 4 2*2 1 (1 + 1) * (1 + 1) = 4 * 1000 27 | 9 3* 3 2 28 | 16 4 * 4 3 29 | 30 | Make sure to write: 31 | 1) clean code 32 | 2) make self-descriptive variables 33 | 34 | """ 35 | import random 36 | from enum import Enum 37 | 38 | def findApproximateValue(initialValue, percentRange = 10): 39 | lowestValue = initialValue - (percentRange / 100) * initialValue 40 | highestValue = initialValue + (percentRange / 100) * initialValue 41 | return random.randint(lowestValue, highestValue) 42 | 43 | 44 | Event = Enum('Event', ['Chest', 'Nothing']) 45 | 46 | eventDictionary = { 47 | Event.Chest: 0.8, 48 | Event.Nothing: 0.2 49 | } 50 | eventList = tuple(eventDictionary.keys()) 51 | eventProbability = tuple(eventDictionary.values()) 52 | 53 | Colours = Enum('Colours', {"Green": "green", 54 | "Orange": "orange", 55 | "Purple": "purple", 56 | "Gold": "LEGENDARY" 57 | }) 58 | 59 | chestColoursDictionary = { 60 | Colours.Green : 0.75, 61 | Colours.Orange : 0.2, 62 | Colours.Purple : 0.04, 63 | Colours.Gold : 0.01 64 | } 65 | chestColourList = tuple(chestColoursDictionary.keys()) 66 | 67 | chestColourProbability = tuple(chestColoursDictionary.values()) 68 | 69 | rewardsForChests = { 70 | chestColourList[reward]: (reward + 1) * (reward + 1) * 1000 71 | for reward in range(4) 72 | } 73 | 74 | gameLength = 5 75 | goldAcquired = 0 76 | while gameLength > 0: 77 | playerAnswer = input("Do you want to move forward?") 78 | if (playerAnswer == "yes"): 79 | print("Great, let's see what you got...") 80 | drawnEvent = random.choices(eventList, eventProbability)[0] 81 | if(drawnEvent == Event.Chest): 82 | print("You've drawn a CHEST") 83 | drawnColour = random.choices(chestColourList, chestColourProbability)[0] 84 | print("The chest color is", drawnColour.value) 85 | playerReward = findApproximateValue(rewardsForChests[drawnColour]) 86 | goldAcquired = goldAcquired + playerReward 87 | elif(drawnEvent == Event.Nothing): 88 | print("You've drawn nothing, you are so unlucky!") 89 | 90 | else: 91 | print("You can go just straight man, nothing else, this game is dumb") 92 | continue 93 | 94 | gameLength = gameLength - 1 95 | 96 | print("Congratulation, you have acquired:", goldAcquired) 97 | 98 | 99 | -------------------------------------------------------------------------------- /60. Files - opening - saving data/openingfiles.py: -------------------------------------------------------------------------------- 1 | """ 2 | FILE - name of location that stores pernamently data 3 | 4 | RAM - temporary data storage 5 | 6 | Operations you can do on a file: 7 | 1) opening 8 | 2) writing/reading 9 | 3) closing 10 | 11 | basic modes(ways) of opening files: 12 | r - R ead - default 13 | w - W rite - if the file existed (will be removed), if not will be created 14 | a - A ppend (adding new content at the end) 15 | 16 | extension is simply saying TEXT that is there only to 17 | make sure other programs know what is inside the 18 | type of file for example txt suggest there is text inside 19 | 20 | """ 21 | 22 | a = 5 23 | 24 | file = open("test.txt", "w") # HANDLER 25 | file.write("SAMPLE") 26 | file.write("SAMPLE") 27 | file.write("SAMPLE") 28 | file.close() 29 | -------------------------------------------------------------------------------- /60. Files - opening - saving data/test.txt: -------------------------------------------------------------------------------- 1 | SAMPLESAMPLESAMPLE -------------------------------------------------------------------------------- /61. Exceptions, try, finally block/openingfiles.py: -------------------------------------------------------------------------------- 1 | """ 2 | FILE - name of location that stores pernamently data 3 | 4 | RAM - temporary data storage 5 | 6 | Operations you can do on a file: 7 | 1) opening 8 | 2) writing/reading 9 | 3) closing 10 | 11 | basic modes(ways) of opening files: 12 | r - R ead - default 13 | w - W rite - if the file existed (will be removed), if not will be created 14 | a - A ppend (adding new content at the end) 15 | 16 | extension is simply saying TEXT that is there only to 17 | make sure other programs know what is inside the 18 | type of file for example txt suggest there is text inside 19 | 20 | 21 | EXCEPTION - an exceptional (unusal) situation in program that makes 22 | your program suddenly stop working 23 | """ 24 | try: 25 | tab = ["a", "b"] 26 | file = open("test.txt", "w") # HANDLER 27 | file.write("SAMPLE") 28 | print(tab[4]) 29 | 30 | file.write("SAMPLE") 31 | finally: #WHAT SHOULD BE DONE ALWAYS 32 | file.close() 33 | 34 | -------------------------------------------------------------------------------- /61. Exceptions, try, finally block/test.txt: -------------------------------------------------------------------------------- 1 | SAMPLE -------------------------------------------------------------------------------- /62. keyword with/openingfiles.py: -------------------------------------------------------------------------------- 1 | """ 2 | FILE - name of location that stores pernamently data 3 | 4 | RAM - temporary data storage 5 | 6 | Operations you can do on a file: 7 | 1) opening 8 | 2) writing/reading 9 | 3) closing 10 | 11 | basic modes(ways) of opening files: 12 | r - R ead - default 13 | w - W rite - if the file existed (will be removed), if not will be created 14 | a - A ppend (adding new content at the end) 15 | 16 | extension is simply saying TEXT that is there only to 17 | make sure other programs know what is inside the 18 | type of file for example txt suggest there is text inside 19 | 20 | 21 | EXCEPTION - an exceptional (unusal) situation in program that makes 22 | your program suddenly stop working 23 | """ 24 | 25 | tab = ["a", "b"] 26 | 27 | with open("test.txt", "w") as file: # HANDLER 28 | file.write("SAMPLE") 29 | print(tab[4]) 30 | 31 | file.write("SAMPLE") 32 | 33 | 34 | -------------------------------------------------------------------------------- /63. reading content from file/namesurnames.txt: -------------------------------------------------------------------------------- 1 | Arkadiusz Włodarczyk 2 | Meadow Dixon 3 | Carla Baker 4 | Lily-May Rosas 5 | Inez Emerson 6 | Stuart Harrington 7 | Lemar Calderon 8 | Zahraa Joyner 9 | Niam Martin 10 | Ezmae Hull 11 | Athena Frost -------------------------------------------------------------------------------- /63. reading content from file/openingfiles.py: -------------------------------------------------------------------------------- 1 | """ 2 | FILE - name of location that stores pernamently data 3 | 4 | RAM - temporary data storage 5 | 6 | Operations you can do on a file: 7 | 1) opening 8 | 2) writing/reading 9 | 3) closing 10 | 11 | basic modes(ways) of opening files: 12 | r - R ead - default 13 | w - W rite - if the file existed (will be removed), if not will be created 14 | a - A ppend (adding new content at the end) 15 | 16 | extension is simply saying TEXT that is there only to 17 | make sure other programs know what is inside the 18 | type of file for example txt suggest there is text inside 19 | 20 | 21 | EXCEPTION - an exceptional (unusal) situation in program that makes 22 | your program suddenly stop working 23 | 24 | read 25 | readline 26 | readlines 27 | 28 | splitlines 29 | """ 30 | 31 | with open("namesurnames.txt", "r", encoding="UTF-8") as file: 32 | for line in file: 33 | print(line, end='') 34 | 35 | 36 | -------------------------------------------------------------------------------- /64. seek and tell/namesurnames.txt: -------------------------------------------------------------------------------- 1 | Arkadiusz Włodarczyk 2 | Meadow 3 | Carla Baker 4 | Lily-May Rosas 5 | Inez Emerson 6 | Stuart Harrington 7 | Lemar Calderon 8 | Zahraa Joyner 9 | Niam Martin 10 | Ezmae Hull 11 | Athena Frost -------------------------------------------------------------------------------- /64. seek and tell/seektell.py: -------------------------------------------------------------------------------- 1 | """ 2 | FILE - name of location that stores pernamently data 3 | 4 | RAM - temporary data storage 5 | 6 | Operations you can do on a file: 7 | 1) opening 8 | 2) writing/reading 9 | 3) closing 10 | 11 | basic modes(ways) of opening files: 12 | r - R ead - default 13 | w - W rite - if the file existed (will be removed), if not will be created 14 | a - A ppend (adding new content at the end) 15 | 16 | extension is simply saying TEXT that is there only to 17 | make sure other programs know what is inside the 18 | type of file for example txt suggest there is text inside 19 | 20 | 21 | EXCEPTION - an exceptional (unusal) situation in program that makes 22 | your program suddenly stop working 23 | 24 | tell - tells, where is the file indicator (file position of last operation) 25 | seek - seeks the indicator and changes its place to the value we want 26 | 27 | JPG 28 | 29 | """ 30 | 31 | with open("namesurnames.txt", "r", encoding="UTF-8") as file: 32 | print(file.readline()) 33 | print(file.tell()) 34 | print(file.readline()) 35 | print(file.tell()) 36 | file.seek(3) 37 | print(file.tell()) 38 | print(file.readline()) 39 | print(file.tell()) 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /65. append - adding new content at the end of file/appendingtext.py: -------------------------------------------------------------------------------- 1 | """ 2 | FILE - name of location that stores pernamently data 3 | 4 | RAM - temporary data storage 5 | 6 | Operations you can do on a file: 7 | 1) opening 8 | 2) writing/reading 9 | 3) closing 10 | 11 | basic modes(ways) of opening files: 12 | r - R ead - default 13 | w - W rite - if the file existed (will be removed), if not will be created 14 | a - A ppend (adding new content at the end) 15 | 16 | extension is simply saying TEXT that is there only to 17 | make sure other programs know what is inside the 18 | type of file for example txt suggest there is text inside 19 | 20 | 21 | EXCEPTION - an exceptional (unusal) situation in program that makes 22 | your program suddenly stop working 23 | 24 | tell - tells, where is the file indicator (file position of last operation) 25 | seek - seeks the indicator and changes its place to the value we want 26 | 27 | JPG 28 | 29 | """ 30 | 31 | with open("namesurnames.txt", "a", encoding="UTF-8") as file: 32 | file.write("Arkadiusz Marx") 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /65. append - adding new content at the end of file/namesurnames.txt: -------------------------------------------------------------------------------- 1 | Arkadiusz Włodarczyk 2 | Meadow 3 | Carla Baker 4 | Lily-May Rosas 5 | Inez Emerson 6 | Stuart Harrington 7 | Lemar Calderon 8 | Zahraa Joyner 9 | Niam Martin 10 | Ezmae Hull 11 | Athena Frost 12 | Arkadiusz Marx -------------------------------------------------------------------------------- /66. a+,w+,r+/additionalfileopeningmodes.py: -------------------------------------------------------------------------------- 1 | """ 2 | basic modes(ways) of opening files: 3 | r - R ead - default 4 | w - W rite - if the file existed (will be removed), if not will be created 5 | a - A ppend (adding new content at the end) 6 | 7 | additional file opening modes: 8 | r+ - allows to read and write 9 | 10 | file.write and file.read 11 | 12 | 13 | w+ - allows to write and read 14 | the difference between r+ and w+ is that it's gonna 15 | remove existing file if there was no file then 16 | it's gonna create a new file 17 | 18 | a+ - "endless" mode of appending and reading 19 | ATTENTION! 20 | write function will ALWAYS append text 21 | even if you change the pointer using "seek" 22 | 23 | if file doesn't exist - it creates it 24 | 25 | 26 | """ 27 | 28 | 29 | with open("namesurnames.txt", "a+", encoding="UTF-8") as file: 30 | file.write("Something at the end") 31 | file.seek(0) 32 | print(file.readline()) 33 | print(file.tell()) 34 | file.write("aaaaa") 35 | 36 | -------------------------------------------------------------------------------- /66. a+,w+,r+/namesurnames.txt: -------------------------------------------------------------------------------- 1 | Arkadiusz Włodarczyk 2 | Meadow 3 | Carla Baker 4 | Lily-May Rosas 5 | Inez Emerson 6 | Stuart Harrington 7 | Lemar Calderon 8 | Zahraa Joyner 9 | Niam Martin 10 | Ezmae Hull 11 | Athena Frost 12 | Arkadiusz MarxSomething at the endSomething at the endSomething at the endaaaaa -------------------------------------------------------------------------------- /67. EXERCISE - names and surnames/names.txt: -------------------------------------------------------------------------------- 1 | Arkadiusz 2 | Meadow 3 | Carla 4 | Lily-May 5 | Inez 6 | Stuart 7 | Lemar 8 | Zahraa 9 | Niam 10 | Ezmae 11 | Athena 12 | Arkadiusz 13 | -------------------------------------------------------------------------------- /67. EXERCISE - names and surnames/namesandsurnames.py: -------------------------------------------------------------------------------- 1 | """ 2 | EXERCISE: 3 | 4 | Load names and surnames from a file called: 5 | namesurnames.txt 6 | 7 | 1) split values. The result should be a list of tuples: 8 | [ 9 | ("Arkadiusz", "Włodarczyk"), 10 | ("Some", "Guy"), 11 | ("Another", "AnotherMan") 12 | ] 13 | 14 | 2) save names to a file called names.txt 15 | 3) save surnames to a file called surnames.txt 16 | 17 | 18 | """ 19 | namesurnames = [] 20 | 21 | with open("namesurnames.txt", "r", encoding="UTF-8") as file: 22 | for line in file: 23 | namesurnames.append(tuple(line.replace("\n", "").split(" "))) 24 | 25 | with open("names.txt", "w", encoding="UTF-8") as file: 26 | for item in namesurnames: 27 | file.write(item[0] + "\n") 28 | 29 | with open("surnames.txt", "w", encoding="UTF-8") as file: 30 | for item in namesurnames: 31 | try: 32 | file.write(item[1] + "\n") 33 | except IndexError: 34 | file.write("\n") 35 | 36 | -------------------------------------------------------------------------------- /67. EXERCISE - names and surnames/namesurnames.txt: -------------------------------------------------------------------------------- 1 | Arkadiusz Włodarczyk 2 | Meadow 3 | Carla Baker 4 | Lily-May Rosas 5 | Inez Emerson 6 | Stuart Harrington 7 | Lemar Calderon 8 | Zahraa Joyner 9 | Niam Martin 10 | Ezmae Hull 11 | Athena Frost 12 | Arkadiusz Marx -------------------------------------------------------------------------------- /67. EXERCISE - names and surnames/surnames.txt: -------------------------------------------------------------------------------- 1 | Włodarczyk 2 | 3 | Baker 4 | Rosas 5 | Emerson 6 | Harrington 7 | Calderon 8 | Joyner 9 | Martin 10 | Hull 11 | Frost 12 | Marx 13 | -------------------------------------------------------------------------------- /68. JSON/json_data_format.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | JSON 4 | 5 | """ 6 | 7 | film = { 8 | "title" : "Nooo I won't do it this way!", 9 | "release_year" : 1969, 10 | "won_oscar" : True, 11 | "actors": ("Arkadiusz Włodarczyk", "Wiolleta Włodarczyk"), 12 | "budget" : None, 13 | "credits" : { 14 | "director" : "Arkadiusz Włodarczyk", 15 | "writer" : "Alan Burger", 16 | "animator" : "Anime Animatrix" 17 | } 18 | } 19 | 20 | 21 | 22 | """ 23 | { 24 | "title":"Nooo I won't do it this way!", 25 | "release_year":1969, 26 | "won_oscar":true, 27 | "actors":[ 28 | "Arkadiusz Włodarczyk", 29 | "Wiolleta Włodarczyk" 30 | ], 31 | "budget":null, 32 | "credits":{ 33 | "director":"Arkadiusz Włodarczyk", 34 | "writer":"Alan Burger", 35 | "animator":"Anime Animatrix" 36 | } 37 | } 38 | """ 39 | 40 | -------------------------------------------------------------------------------- /69. Saving data to JSON format/json_data_format.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | json.dumps(data) - saves data in String format to JSON 4 | json.dump(data, nameOfFileHandler, ensure_ascii=False) - 5 | saves data to nameOfFileHandler in JSON format 6 | 7 | dump means drop, throw away, ditch 8 | """ 9 | 10 | import json 11 | 12 | movie = { 13 | "title" : "But I won't do it!", 14 | "release_year" : 1969, 15 | "won_oscar" : True, 16 | "actors": ("Arkadiusz Włodarczyk", "Wiolleta Włodarczyk"), 17 | "budget" : None, 18 | "credits" : { 19 | "director" : "Arkadiusz Włodarczyk", 20 | "writer" : "Alan Burger", 21 | "animator" : "Anime Animatrix" 22 | } 23 | } 24 | 25 | encodedMovie = json.dumps(movie, ensure_ascii=False) 26 | 27 | with open("sample.json", "w", encoding="UTF-8") as file: 28 | json.dump(movie, file, ensure_ascii = False) 29 | """ 30 | { 31 | "title":"Ale ja nie będę tego robił!", 32 | "release_year":1969, 33 | "won_oscar":true, 34 | "actors":[ 35 | "Arkadiusz Włodarczyk", 36 | "Wiolleta Włodarczyk" 37 | ], 38 | "budget":null, 39 | "credits":{ 40 | "director":"Arkadiusz Włodarczyk", 41 | "writer":"Alan Burger", 42 | "animator":"Anime Animatrix" 43 | } 44 | } 45 | """ 46 | 47 | -------------------------------------------------------------------------------- /69. Saving data to JSON format/sample.json: -------------------------------------------------------------------------------- 1 | {"title": "But I won't do it!", "release_year": 1969, "won_oscar": true, "actors": ["Arkadiusz Włodarczyk", "Wiolleta Włodarczyk"], "budget": null, "credits": {"director": "Arkadiusz Włodarczyk", "writer": "Alan Burger", "animator": "Anime Animatrix"}} -------------------------------------------------------------------------------- /70. Loading data from JSON to Python/json_data_format.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | json.loads(jsonstring) - process jsonstring to Python type 4 | 5 | json.load(filePointer) - loads json from a file 6 | and returns as a result of method Python type 7 | 8 | """ 9 | 10 | import json 11 | 12 | film = { 13 | "title" : "But I won't do it!", 14 | "release_year" : 1969, 15 | "won_oscar" : True, 16 | "actors": ("Arkadiusz Włodarczyk", "Wiolleta Włodarczyk"), 17 | "budget" : None, 18 | "credits" : { 19 | "director" : "Arkadiusz Włodarczyk", 20 | "writer" : "Alan Burger", 21 | "animator" : "Anime Animatrix" 22 | } 23 | } 24 | 25 | encodedRetrievedMovie = '{"title": "But I won\'t do it!!", "release_year": 1969, "won_oscar": true, "actors": ["Arkadiusz Włodarczyk", "Wiolleta Włodarczyk"], "budget": null, "credits": {"director": "Arkadiusz Włodarczyk", "writer": "Alan Burger", "animator": "Anime Animatrix"}}' 26 | 27 | decodedMovie = json.loads(encodedRetrievedMovie) 28 | 29 | with open("sample.json", encoding="UTF-8") as file: 30 | result = json.load(file) 31 | 32 | -------------------------------------------------------------------------------- /70. Loading data from JSON to Python/sample.json: -------------------------------------------------------------------------------- 1 | {"title": "But I won't do it!", "release_year": 1969, "won_oscar": true, "actors": ["Arkadiusz Włodarczyk", "Wiolleta Włodarczyk"], "budget": null, "credits": {"director": "Arkadiusz Włodarczyk", "writer": "Alan Burger", "animator": "Anime Animatrix"}} -------------------------------------------------------------------------------- /71. Pretty printing JSON format in Shell and file/prettyprinting.py: -------------------------------------------------------------------------------- 1 | """ 2 | pretty print (pprint) 3 | 4 | """ 5 | 6 | import json 7 | 8 | movie = { 9 | "title" : "But I won't do it!", 10 | "release_year" : 1969, 11 | "won_oscar" : True, 12 | "actors": ("Arkadiusz Włodarczyk", "Wiolleta Włodarczyk"), 13 | "budget" : None, 14 | "credits" : { 15 | "director" : "Arkadiusz Włodarczyk", 16 | "writer" : "Alan Burger", 17 | "animator" : "Anime Animatrix" 18 | } 19 | } 20 | 21 | encodedMovie = json.dumps(movie, ensure_ascii=False, indent=4, sort_keys=True) 22 | 23 | with open("sample.json", "w", encoding="UTF-8") as file: 24 | json.dump(movie, file, ensure_ascii = False, indent=4, sort_keys=True) 25 | 26 | 27 | with open("sample.json", encoding="UTF-8") as file: 28 | result = json.load(file) 29 | 30 | print(json.dumps(result, indent=4, ensure_ascii=False, sort_keys=True)) 31 | 32 | import pprint 33 | 34 | pprint.pprint(result) 35 | -------------------------------------------------------------------------------- /71. Pretty printing JSON format in Shell and file/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "actors": [ 3 | "Arkadiusz Włodarczyk", 4 | "Wiolleta Włodarczyk" 5 | ], 6 | "budget": null, 7 | "credits": { 8 | "animator": "Anime Animatrix", 9 | "director": "Arkadiusz Włodarczyk", 10 | "writer": "Alan Burger" 11 | }, 12 | "release_year": 1969, 13 | "title": "But I won't do it!", 14 | "won_oscar": true 15 | } -------------------------------------------------------------------------------- /72. Installing external package - requests - PIP -PyPi/EXERCISE - Filter Pages.DOC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/72. Installing external package - requests - PIP -PyPi/EXERCISE - Filter Pages.DOC -------------------------------------------------------------------------------- /72. Installing external package - requests - PIP -PyPi/Fixes for pip if it's not working.txt: -------------------------------------------------------------------------------- 1 | Fixes for pip if it's not working 2 | https://appuals.com/fix-pip-is-not-recognized-as-an-internal-or-external-command/ -------------------------------------------------------------------------------- /72. Installing external package - requests - PIP -PyPi/requests_api.py: -------------------------------------------------------------------------------- 1 | """ 2 | pip - pip installs packages - package installer 3 | 4 | PyPi - Python Package index - list of external packages written in Python 5 | 6 | WRITE a function that will open website provided as argument 7 | 8 | create a list of websites 9 | 10 | create a list of websites that DIDn't open properly (404) 11 | 12 | save all these not opening websites into a file 13 | save all websites that are opening into another file 14 | 15 | 16 | 17 | """ 18 | 19 | import requests 20 | 21 | response = requests.get("http://github.com") 22 | -------------------------------------------------------------------------------- /73. Loading data from server from JSON file - preface to next EXERCISE/jsplaceholder.py: -------------------------------------------------------------------------------- 1 | """ 2 | JSONplaceholder 3 | 4 | idTask 5 | idUser 6 | taskContent 7 | completed 8 | 9 | """ 10 | 11 | import requests 12 | import json 13 | 14 | response = requests.get("https://jsonplaceholder.typicode.com/todos") 15 | 16 | #tasks = json.loads(response.text) 17 | try: 18 | tasks = response.json() 19 | except json.decoder.JSONDecodeError: 20 | print("The content is not JSON") 21 | else: 22 | print("THIS IS A PLACE WHERE YOU SHOULD PUT A CODE if everything went fine") 23 | print(tasks[0]) 24 | -------------------------------------------------------------------------------- /74. Processing JSON data from server/jsplaceholder.py: -------------------------------------------------------------------------------- 1 | """ 2 | Our JSON data looks like that: 3 | idTask 4 | idUser 5 | taskContent 6 | completed 7 | 8 | 9 | idUser when 10 | completed == "true" 11 | 12 | and save each occurence/appearance/manifestation in format: 13 | 14 | { 15 | 1 : 11 16 | 2 : 8 17 | 3 : 5 18 | 19 | #and so on 20 | } 21 | 22 | """ 23 | 24 | import requests 25 | import json 26 | 27 | response = requests.get("https://jsonplaceholder.typicode.com/todos") 28 | 29 | #tasks = json.loads(response.text) 30 | try: 31 | tasks = response.json() 32 | except json.decoder.JSONDecodeError: 33 | print("The content is not JSON") 34 | else: 35 | completedTasksFrequencyByUser = dict() 36 | for entry in tasks: 37 | if (entry["completed"] == True): 38 | try: 39 | completedTasksFrequencyByUser[entry["userId"]] += 1 40 | except KeyError: 41 | completedTasksFrequencyByUser[entry["userId"]] = 1 42 | 43 | usersIdWithMaxCompletedAmountOfTasks = [] 44 | for userId, numberOfCompletedTasks in completedTasksFrequencyByUser.items(): 45 | maxAmountOfCompletedTasks = max(completedTasksFrequencyByUser.values()) 46 | if (numberOfCompletedTasks == maxAmountOfCompletedTasks): 47 | usersIdWithMaxCompletedAmountOfTasks.append(userId) 48 | 49 | print("Cookies for: ", usersIdWithMaxCompletedAmountOfTasks) 50 | 51 | -------------------------------------------------------------------------------- /74. Processing JSON data from server/todos.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "userId": 1, 4 | "id": 1, 5 | "title": "delectus aut autem", 6 | "completed": false 7 | }, 8 | { 9 | "userId": 1, 10 | "id": 2, 11 | "title": "quis ut nam facilis et officia qui", 12 | "completed": false 13 | }, 14 | { 15 | "userId": 1, 16 | "id": 3, 17 | "title": "fugiat veniam minus", 18 | "completed": false 19 | }, 20 | { 21 | "userId": 1, 22 | "id": 4, 23 | "title": "et porro tempora", 24 | "completed": true 25 | }, 26 | { 27 | "userId": 1, 28 | "id": 5, 29 | "title": "laboriosam mollitia et enim quasi adipisci quia provident illum", 30 | "completed": false 31 | }, 32 | { 33 | "userId": 1, 34 | "id": 6, 35 | "title": "qui ullam ratione quibusdam voluptatem quia omnis", 36 | "completed": false 37 | }, 38 | { 39 | "userId": 1, 40 | "id": 7, 41 | "title": "illo expedita consequatur quia in", 42 | "completed": false 43 | }, 44 | { 45 | "userId": 1, 46 | "id": 8, 47 | "title": "quo adipisci enim quam ut ab", 48 | "completed": true 49 | }, 50 | { 51 | "userId": 1, 52 | "id": 9, 53 | "title": "molestiae perspiciatis ipsa", 54 | "completed": false 55 | }, 56 | { 57 | "userId": 1, 58 | "id": 10, 59 | "title": "illo est ratione doloremque quia maiores aut", 60 | "completed": true 61 | }, 62 | { 63 | "userId": 1, 64 | "id": 11, 65 | "title": "vero rerum temporibus dolor", 66 | "completed": true 67 | }, 68 | { 69 | "userId": 1, 70 | "id": 12, 71 | "title": "ipsa repellendus fugit nisi", 72 | "completed": true 73 | }, 74 | { 75 | "userId": 1, 76 | "id": 13, 77 | "title": "et doloremque nulla", 78 | "completed": false 79 | }, 80 | { 81 | "userId": 1, 82 | "id": 14, 83 | "title": "repellendus sunt dolores architecto voluptatum", 84 | "completed": true 85 | }, 86 | { 87 | "userId": 1, 88 | "id": 15, 89 | "title": "ab voluptatum amet voluptas", 90 | "completed": true 91 | }, 92 | { 93 | "userId": 1, 94 | "id": 16, 95 | "title": "accusamus eos facilis sint et aut voluptatem", 96 | "completed": true 97 | }, 98 | { 99 | "userId": 1, 100 | "id": 17, 101 | "title": "quo laboriosam deleniti aut qui", 102 | "completed": true 103 | }, 104 | { 105 | "userId": 1, 106 | "id": 18, 107 | "title": "dolorum est consequatur ea mollitia in culpa", 108 | "completed": false 109 | }, 110 | { 111 | "userId": 1, 112 | "id": 19, 113 | "title": "molestiae ipsa aut voluptatibus pariatur dolor nihil", 114 | "completed": true 115 | }, 116 | { 117 | "userId": 1, 118 | "id": 20, 119 | "title": "ullam nobis libero sapiente ad optio sint", 120 | "completed": true 121 | }, 122 | { 123 | "userId": 2, 124 | "id": 21, 125 | "title": "suscipit repellat esse quibusdam voluptatem incidunt", 126 | "completed": false 127 | }, 128 | { 129 | "userId": 2, 130 | "id": 22, 131 | "title": "distinctio vitae autem nihil ut molestias quo", 132 | "completed": true 133 | }, 134 | { 135 | "userId": 2, 136 | "id": 23, 137 | "title": "et itaque necessitatibus maxime molestiae qui quas velit", 138 | "completed": false 139 | }, 140 | { 141 | "userId": 2, 142 | "id": 24, 143 | "title": "adipisci non ad dicta qui amet quaerat doloribus ea", 144 | "completed": false 145 | }, 146 | { 147 | "userId": 2, 148 | "id": 25, 149 | "title": "voluptas quo tenetur perspiciatis explicabo natus", 150 | "completed": true 151 | }, 152 | { 153 | "userId": 2, 154 | "id": 26, 155 | "title": "aliquam aut quasi", 156 | "completed": true 157 | }, 158 | { 159 | "userId": 2, 160 | "id": 27, 161 | "title": "veritatis pariatur delectus", 162 | "completed": true 163 | }, 164 | { 165 | "userId": 2, 166 | "id": 28, 167 | "title": "nesciunt totam sit blanditiis sit", 168 | "completed": false 169 | }, 170 | { 171 | "userId": 2, 172 | "id": 29, 173 | "title": "laborum aut in quam", 174 | "completed": false 175 | }, 176 | { 177 | "userId": 2, 178 | "id": 30, 179 | "title": "nemo perspiciatis repellat ut dolor libero commodi blanditiis omnis", 180 | "completed": true 181 | }, 182 | { 183 | "userId": 2, 184 | "id": 31, 185 | "title": "repudiandae totam in est sint facere fuga", 186 | "completed": false 187 | }, 188 | { 189 | "userId": 2, 190 | "id": 32, 191 | "title": "earum doloribus ea doloremque quis", 192 | "completed": false 193 | }, 194 | { 195 | "userId": 2, 196 | "id": 33, 197 | "title": "sint sit aut vero", 198 | "completed": false 199 | }, 200 | { 201 | "userId": 2, 202 | "id": 34, 203 | "title": "porro aut necessitatibus eaque distinctio", 204 | "completed": false 205 | }, 206 | { 207 | "userId": 2, 208 | "id": 35, 209 | "title": "repellendus veritatis molestias dicta incidunt", 210 | "completed": true 211 | }, 212 | { 213 | "userId": 2, 214 | "id": 36, 215 | "title": "excepturi deleniti adipisci voluptatem et neque optio illum ad", 216 | "completed": true 217 | }, 218 | { 219 | "userId": 2, 220 | "id": 37, 221 | "title": "sunt cum tempora", 222 | "completed": false 223 | }, 224 | { 225 | "userId": 2, 226 | "id": 38, 227 | "title": "totam quia non", 228 | "completed": false 229 | }, 230 | { 231 | "userId": 2, 232 | "id": 39, 233 | "title": "doloremque quibusdam asperiores libero corrupti illum qui omnis", 234 | "completed": false 235 | }, 236 | { 237 | "userId": 2, 238 | "id": 40, 239 | "title": "totam atque quo nesciunt", 240 | "completed": true 241 | }, 242 | { 243 | "userId": 3, 244 | "id": 41, 245 | "title": "aliquid amet impedit consequatur aspernatur placeat eaque fugiat suscipit", 246 | "completed": false 247 | }, 248 | { 249 | "userId": 3, 250 | "id": 42, 251 | "title": "rerum perferendis error quia ut eveniet", 252 | "completed": false 253 | }, 254 | { 255 | "userId": 3, 256 | "id": 43, 257 | "title": "tempore ut sint quis recusandae", 258 | "completed": true 259 | }, 260 | { 261 | "userId": 3, 262 | "id": 44, 263 | "title": "cum debitis quis accusamus doloremque ipsa natus sapiente omnis", 264 | "completed": true 265 | }, 266 | { 267 | "userId": 3, 268 | "id": 45, 269 | "title": "velit soluta adipisci molestias reiciendis harum", 270 | "completed": false 271 | }, 272 | { 273 | "userId": 3, 274 | "id": 46, 275 | "title": "vel voluptatem repellat nihil placeat corporis", 276 | "completed": false 277 | }, 278 | { 279 | "userId": 3, 280 | "id": 47, 281 | "title": "nam qui rerum fugiat accusamus", 282 | "completed": false 283 | }, 284 | { 285 | "userId": 3, 286 | "id": 48, 287 | "title": "sit reprehenderit omnis quia", 288 | "completed": false 289 | }, 290 | { 291 | "userId": 3, 292 | "id": 49, 293 | "title": "ut necessitatibus aut maiores debitis officia blanditiis velit et", 294 | "completed": false 295 | }, 296 | { 297 | "userId": 3, 298 | "id": 50, 299 | "title": "cupiditate necessitatibus ullam aut quis dolor voluptate", 300 | "completed": true 301 | }, 302 | { 303 | "userId": 3, 304 | "id": 51, 305 | "title": "distinctio exercitationem ab doloribus", 306 | "completed": false 307 | }, 308 | { 309 | "userId": 3, 310 | "id": 52, 311 | "title": "nesciunt dolorum quis recusandae ad pariatur ratione", 312 | "completed": false 313 | }, 314 | { 315 | "userId": 3, 316 | "id": 53, 317 | "title": "qui labore est occaecati recusandae aliquid quam", 318 | "completed": false 319 | }, 320 | { 321 | "userId": 3, 322 | "id": 54, 323 | "title": "quis et est ut voluptate quam dolor", 324 | "completed": true 325 | }, 326 | { 327 | "userId": 3, 328 | "id": 55, 329 | "title": "voluptatum omnis minima qui occaecati provident nulla voluptatem ratione", 330 | "completed": true 331 | }, 332 | { 333 | "userId": 3, 334 | "id": 56, 335 | "title": "deleniti ea temporibus enim", 336 | "completed": true 337 | }, 338 | { 339 | "userId": 3, 340 | "id": 57, 341 | "title": "pariatur et magnam ea doloribus similique voluptatem rerum quia", 342 | "completed": false 343 | }, 344 | { 345 | "userId": 3, 346 | "id": 58, 347 | "title": "est dicta totam qui explicabo doloribus qui dignissimos", 348 | "completed": false 349 | }, 350 | { 351 | "userId": 3, 352 | "id": 59, 353 | "title": "perspiciatis velit id laborum placeat iusto et aliquam odio", 354 | "completed": false 355 | }, 356 | { 357 | "userId": 3, 358 | "id": 60, 359 | "title": "et sequi qui architecto ut adipisci", 360 | "completed": true 361 | }, 362 | { 363 | "userId": 4, 364 | "id": 61, 365 | "title": "odit optio omnis qui sunt", 366 | "completed": true 367 | }, 368 | { 369 | "userId": 4, 370 | "id": 62, 371 | "title": "et placeat et tempore aspernatur sint numquam", 372 | "completed": false 373 | }, 374 | { 375 | "userId": 4, 376 | "id": 63, 377 | "title": "doloremque aut dolores quidem fuga qui nulla", 378 | "completed": true 379 | }, 380 | { 381 | "userId": 4, 382 | "id": 64, 383 | "title": "voluptas consequatur qui ut quia magnam nemo esse", 384 | "completed": false 385 | }, 386 | { 387 | "userId": 4, 388 | "id": 65, 389 | "title": "fugiat pariatur ratione ut asperiores necessitatibus magni", 390 | "completed": false 391 | }, 392 | { 393 | "userId": 4, 394 | "id": 66, 395 | "title": "rerum eum molestias autem voluptatum sit optio", 396 | "completed": false 397 | }, 398 | { 399 | "userId": 4, 400 | "id": 67, 401 | "title": "quia voluptatibus voluptatem quos similique maiores repellat", 402 | "completed": false 403 | }, 404 | { 405 | "userId": 4, 406 | "id": 68, 407 | "title": "aut id perspiciatis voluptatem iusto", 408 | "completed": false 409 | }, 410 | { 411 | "userId": 4, 412 | "id": 69, 413 | "title": "doloribus sint dolorum ab adipisci itaque dignissimos aliquam suscipit", 414 | "completed": false 415 | }, 416 | { 417 | "userId": 4, 418 | "id": 70, 419 | "title": "ut sequi accusantium et mollitia delectus sunt", 420 | "completed": false 421 | }, 422 | { 423 | "userId": 4, 424 | "id": 71, 425 | "title": "aut velit saepe ullam", 426 | "completed": false 427 | }, 428 | { 429 | "userId": 4, 430 | "id": 72, 431 | "title": "praesentium facilis facere quis harum voluptatibus voluptatem eum", 432 | "completed": false 433 | }, 434 | { 435 | "userId": 4, 436 | "id": 73, 437 | "title": "sint amet quia totam corporis qui exercitationem commodi", 438 | "completed": true 439 | }, 440 | { 441 | "userId": 4, 442 | "id": 74, 443 | "title": "expedita tempore nobis eveniet laborum maiores", 444 | "completed": false 445 | }, 446 | { 447 | "userId": 4, 448 | "id": 75, 449 | "title": "occaecati adipisci est possimus totam", 450 | "completed": false 451 | }, 452 | { 453 | "userId": 4, 454 | "id": 76, 455 | "title": "sequi dolorem sed", 456 | "completed": true 457 | }, 458 | { 459 | "userId": 4, 460 | "id": 77, 461 | "title": "maiores aut nesciunt delectus exercitationem vel assumenda eligendi at", 462 | "completed": false 463 | }, 464 | { 465 | "userId": 4, 466 | "id": 78, 467 | "title": "reiciendis est magnam amet nemo iste recusandae impedit quaerat", 468 | "completed": false 469 | }, 470 | { 471 | "userId": 4, 472 | "id": 79, 473 | "title": "eum ipsa maxime ut", 474 | "completed": true 475 | }, 476 | { 477 | "userId": 4, 478 | "id": 80, 479 | "title": "tempore molestias dolores rerum sequi voluptates ipsum consequatur", 480 | "completed": true 481 | }, 482 | { 483 | "userId": 5, 484 | "id": 81, 485 | "title": "suscipit qui totam", 486 | "completed": true 487 | }, 488 | { 489 | "userId": 5, 490 | "id": 82, 491 | "title": "voluptates eum voluptas et dicta", 492 | "completed": false 493 | }, 494 | { 495 | "userId": 5, 496 | "id": 83, 497 | "title": "quidem at rerum quis ex aut sit quam", 498 | "completed": true 499 | }, 500 | { 501 | "userId": 5, 502 | "id": 84, 503 | "title": "sunt veritatis ut voluptate", 504 | "completed": false 505 | }, 506 | { 507 | "userId": 5, 508 | "id": 85, 509 | "title": "et quia ad iste a", 510 | "completed": true 511 | }, 512 | { 513 | "userId": 5, 514 | "id": 86, 515 | "title": "incidunt ut saepe autem", 516 | "completed": true 517 | }, 518 | { 519 | "userId": 5, 520 | "id": 87, 521 | "title": "laudantium quae eligendi consequatur quia et vero autem", 522 | "completed": true 523 | }, 524 | { 525 | "userId": 5, 526 | "id": 88, 527 | "title": "vitae aut excepturi laboriosam sint aliquam et et accusantium", 528 | "completed": false 529 | }, 530 | { 531 | "userId": 5, 532 | "id": 89, 533 | "title": "sequi ut omnis et", 534 | "completed": true 535 | }, 536 | { 537 | "userId": 5, 538 | "id": 90, 539 | "title": "molestiae nisi accusantium tenetur dolorem et", 540 | "completed": true 541 | }, 542 | { 543 | "userId": 5, 544 | "id": 91, 545 | "title": "nulla quis consequatur saepe qui id expedita", 546 | "completed": true 547 | }, 548 | { 549 | "userId": 5, 550 | "id": 92, 551 | "title": "in omnis laboriosam", 552 | "completed": true 553 | }, 554 | { 555 | "userId": 5, 556 | "id": 93, 557 | "title": "odio iure consequatur molestiae quibusdam necessitatibus quia sint", 558 | "completed": true 559 | }, 560 | { 561 | "userId": 5, 562 | "id": 94, 563 | "title": "facilis modi saepe mollitia", 564 | "completed": false 565 | }, 566 | { 567 | "userId": 5, 568 | "id": 95, 569 | "title": "vel nihil et molestiae iusto assumenda nemo quo ut", 570 | "completed": true 571 | }, 572 | { 573 | "userId": 5, 574 | "id": 96, 575 | "title": "nobis suscipit ducimus enim asperiores voluptas", 576 | "completed": false 577 | }, 578 | { 579 | "userId": 5, 580 | "id": 97, 581 | "title": "dolorum laboriosam eos qui iure aliquam", 582 | "completed": false 583 | }, 584 | { 585 | "userId": 5, 586 | "id": 98, 587 | "title": "debitis accusantium ut quo facilis nihil quis sapiente necessitatibus", 588 | "completed": true 589 | }, 590 | { 591 | "userId": 5, 592 | "id": 99, 593 | "title": "neque voluptates ratione", 594 | "completed": false 595 | }, 596 | { 597 | "userId": 5, 598 | "id": 100, 599 | "title": "excepturi a et neque qui expedita vel voluptate", 600 | "completed": false 601 | }, 602 | { 603 | "userId": 6, 604 | "id": 101, 605 | "title": "explicabo enim cumque porro aperiam occaecati minima", 606 | "completed": false 607 | }, 608 | { 609 | "userId": 6, 610 | "id": 102, 611 | "title": "sed ab consequatur", 612 | "completed": false 613 | }, 614 | { 615 | "userId": 6, 616 | "id": 103, 617 | "title": "non sunt delectus illo nulla tenetur enim omnis", 618 | "completed": false 619 | }, 620 | { 621 | "userId": 6, 622 | "id": 104, 623 | "title": "excepturi non laudantium quo", 624 | "completed": false 625 | }, 626 | { 627 | "userId": 6, 628 | "id": 105, 629 | "title": "totam quia dolorem et illum repellat voluptas optio", 630 | "completed": true 631 | }, 632 | { 633 | "userId": 6, 634 | "id": 106, 635 | "title": "ad illo quis voluptatem temporibus", 636 | "completed": true 637 | }, 638 | { 639 | "userId": 6, 640 | "id": 107, 641 | "title": "praesentium facilis omnis laudantium fugit ad iusto nihil nesciunt", 642 | "completed": false 643 | }, 644 | { 645 | "userId": 6, 646 | "id": 108, 647 | "title": "a eos eaque nihil et exercitationem incidunt delectus", 648 | "completed": true 649 | }, 650 | { 651 | "userId": 6, 652 | "id": 109, 653 | "title": "autem temporibus harum quisquam in culpa", 654 | "completed": true 655 | }, 656 | { 657 | "userId": 6, 658 | "id": 110, 659 | "title": "aut aut ea corporis", 660 | "completed": true 661 | }, 662 | { 663 | "userId": 6, 664 | "id": 111, 665 | "title": "magni accusantium labore et id quis provident", 666 | "completed": false 667 | }, 668 | { 669 | "userId": 6, 670 | "id": 112, 671 | "title": "consectetur impedit quisquam qui deserunt non rerum consequuntur eius", 672 | "completed": false 673 | }, 674 | { 675 | "userId": 6, 676 | "id": 113, 677 | "title": "quia atque aliquam sunt impedit voluptatum rerum assumenda nisi", 678 | "completed": false 679 | }, 680 | { 681 | "userId": 6, 682 | "id": 114, 683 | "title": "cupiditate quos possimus corporis quisquam exercitationem beatae", 684 | "completed": false 685 | }, 686 | { 687 | "userId": 6, 688 | "id": 115, 689 | "title": "sed et ea eum", 690 | "completed": false 691 | }, 692 | { 693 | "userId": 6, 694 | "id": 116, 695 | "title": "ipsa dolores vel facilis ut", 696 | "completed": true 697 | }, 698 | { 699 | "userId": 6, 700 | "id": 117, 701 | "title": "sequi quae est et qui qui eveniet asperiores", 702 | "completed": false 703 | }, 704 | { 705 | "userId": 6, 706 | "id": 118, 707 | "title": "quia modi consequatur vero fugiat", 708 | "completed": false 709 | }, 710 | { 711 | "userId": 6, 712 | "id": 119, 713 | "title": "corporis ducimus ea perspiciatis iste", 714 | "completed": false 715 | }, 716 | { 717 | "userId": 6, 718 | "id": 120, 719 | "title": "dolorem laboriosam vel voluptas et aliquam quasi", 720 | "completed": false 721 | }, 722 | { 723 | "userId": 7, 724 | "id": 121, 725 | "title": "inventore aut nihil minima laudantium hic qui omnis", 726 | "completed": true 727 | }, 728 | { 729 | "userId": 7, 730 | "id": 122, 731 | "title": "provident aut nobis culpa", 732 | "completed": true 733 | }, 734 | { 735 | "userId": 7, 736 | "id": 123, 737 | "title": "esse et quis iste est earum aut impedit", 738 | "completed": false 739 | }, 740 | { 741 | "userId": 7, 742 | "id": 124, 743 | "title": "qui consectetur id", 744 | "completed": false 745 | }, 746 | { 747 | "userId": 7, 748 | "id": 125, 749 | "title": "aut quasi autem iste tempore illum possimus", 750 | "completed": false 751 | }, 752 | { 753 | "userId": 7, 754 | "id": 126, 755 | "title": "ut asperiores perspiciatis veniam ipsum rerum saepe", 756 | "completed": true 757 | }, 758 | { 759 | "userId": 7, 760 | "id": 127, 761 | "title": "voluptatem libero consectetur rerum ut", 762 | "completed": true 763 | }, 764 | { 765 | "userId": 7, 766 | "id": 128, 767 | "title": "eius omnis est qui voluptatem autem", 768 | "completed": false 769 | }, 770 | { 771 | "userId": 7, 772 | "id": 129, 773 | "title": "rerum culpa quis harum", 774 | "completed": false 775 | }, 776 | { 777 | "userId": 7, 778 | "id": 130, 779 | "title": "nulla aliquid eveniet harum laborum libero alias ut unde", 780 | "completed": true 781 | }, 782 | { 783 | "userId": 7, 784 | "id": 131, 785 | "title": "qui ea incidunt quis", 786 | "completed": false 787 | }, 788 | { 789 | "userId": 7, 790 | "id": 132, 791 | "title": "qui molestiae voluptatibus velit iure harum quisquam", 792 | "completed": true 793 | }, 794 | { 795 | "userId": 7, 796 | "id": 133, 797 | "title": "et labore eos enim rerum consequatur sunt", 798 | "completed": true 799 | }, 800 | { 801 | "userId": 7, 802 | "id": 134, 803 | "title": "molestiae doloribus et laborum quod ea", 804 | "completed": false 805 | }, 806 | { 807 | "userId": 7, 808 | "id": 135, 809 | "title": "facere ipsa nam eum voluptates reiciendis vero qui", 810 | "completed": false 811 | }, 812 | { 813 | "userId": 7, 814 | "id": 136, 815 | "title": "asperiores illo tempora fuga sed ut quasi adipisci", 816 | "completed": false 817 | }, 818 | { 819 | "userId": 7, 820 | "id": 137, 821 | "title": "qui sit non", 822 | "completed": false 823 | }, 824 | { 825 | "userId": 7, 826 | "id": 138, 827 | "title": "placeat minima consequatur rem qui ut", 828 | "completed": true 829 | }, 830 | { 831 | "userId": 7, 832 | "id": 139, 833 | "title": "consequatur doloribus id possimus voluptas a voluptatem", 834 | "completed": false 835 | }, 836 | { 837 | "userId": 7, 838 | "id": 140, 839 | "title": "aut consectetur in blanditiis deserunt quia sed laboriosam", 840 | "completed": true 841 | }, 842 | { 843 | "userId": 8, 844 | "id": 141, 845 | "title": "explicabo consectetur debitis voluptates quas quae culpa rerum non", 846 | "completed": true 847 | }, 848 | { 849 | "userId": 8, 850 | "id": 142, 851 | "title": "maiores accusantium architecto necessitatibus reiciendis ea aut", 852 | "completed": true 853 | }, 854 | { 855 | "userId": 8, 856 | "id": 143, 857 | "title": "eum non recusandae cupiditate animi", 858 | "completed": false 859 | }, 860 | { 861 | "userId": 8, 862 | "id": 144, 863 | "title": "ut eum exercitationem sint", 864 | "completed": false 865 | }, 866 | { 867 | "userId": 8, 868 | "id": 145, 869 | "title": "beatae qui ullam incidunt voluptatem non nisi aliquam", 870 | "completed": false 871 | }, 872 | { 873 | "userId": 8, 874 | "id": 146, 875 | "title": "molestiae suscipit ratione nihil odio libero impedit vero totam", 876 | "completed": true 877 | }, 878 | { 879 | "userId": 8, 880 | "id": 147, 881 | "title": "eum itaque quod reprehenderit et facilis dolor autem ut", 882 | "completed": true 883 | }, 884 | { 885 | "userId": 8, 886 | "id": 148, 887 | "title": "esse quas et quo quasi exercitationem", 888 | "completed": false 889 | }, 890 | { 891 | "userId": 8, 892 | "id": 149, 893 | "title": "animi voluptas quod perferendis est", 894 | "completed": false 895 | }, 896 | { 897 | "userId": 8, 898 | "id": 150, 899 | "title": "eos amet tempore laudantium fugit a", 900 | "completed": false 901 | }, 902 | { 903 | "userId": 8, 904 | "id": 151, 905 | "title": "accusamus adipisci dicta qui quo ea explicabo sed vero", 906 | "completed": true 907 | }, 908 | { 909 | "userId": 8, 910 | "id": 152, 911 | "title": "odit eligendi recusandae doloremque cumque non", 912 | "completed": false 913 | }, 914 | { 915 | "userId": 8, 916 | "id": 153, 917 | "title": "ea aperiam consequatur qui repellat eos", 918 | "completed": false 919 | }, 920 | { 921 | "userId": 8, 922 | "id": 154, 923 | "title": "rerum non ex sapiente", 924 | "completed": true 925 | }, 926 | { 927 | "userId": 8, 928 | "id": 155, 929 | "title": "voluptatem nobis consequatur et assumenda magnam", 930 | "completed": true 931 | }, 932 | { 933 | "userId": 8, 934 | "id": 156, 935 | "title": "nam quia quia nulla repellat assumenda quibusdam sit nobis", 936 | "completed": true 937 | }, 938 | { 939 | "userId": 8, 940 | "id": 157, 941 | "title": "dolorem veniam quisquam deserunt repellendus", 942 | "completed": true 943 | }, 944 | { 945 | "userId": 8, 946 | "id": 158, 947 | "title": "debitis vitae delectus et harum accusamus aut deleniti a", 948 | "completed": true 949 | }, 950 | { 951 | "userId": 8, 952 | "id": 159, 953 | "title": "debitis adipisci quibusdam aliquam sed dolore ea praesentium nobis", 954 | "completed": true 955 | }, 956 | { 957 | "userId": 8, 958 | "id": 160, 959 | "title": "et praesentium aliquam est", 960 | "completed": false 961 | }, 962 | { 963 | "userId": 9, 964 | "id": 161, 965 | "title": "ex hic consequuntur earum omnis alias ut occaecati culpa", 966 | "completed": true 967 | }, 968 | { 969 | "userId": 9, 970 | "id": 162, 971 | "title": "omnis laboriosam molestias animi sunt dolore", 972 | "completed": true 973 | }, 974 | { 975 | "userId": 9, 976 | "id": 163, 977 | "title": "natus corrupti maxime laudantium et voluptatem laboriosam odit", 978 | "completed": false 979 | }, 980 | { 981 | "userId": 9, 982 | "id": 164, 983 | "title": "reprehenderit quos aut aut consequatur est sed", 984 | "completed": false 985 | }, 986 | { 987 | "userId": 9, 988 | "id": 165, 989 | "title": "fugiat perferendis sed aut quidem", 990 | "completed": false 991 | }, 992 | { 993 | "userId": 9, 994 | "id": 166, 995 | "title": "quos quo possimus suscipit minima ut", 996 | "completed": false 997 | }, 998 | { 999 | "userId": 9, 1000 | "id": 167, 1001 | "title": "et quis minus quo a asperiores molestiae", 1002 | "completed": false 1003 | }, 1004 | { 1005 | "userId": 9, 1006 | "id": 168, 1007 | "title": "recusandae quia qui sunt libero", 1008 | "completed": false 1009 | }, 1010 | { 1011 | "userId": 9, 1012 | "id": 169, 1013 | "title": "ea odio perferendis officiis", 1014 | "completed": true 1015 | }, 1016 | { 1017 | "userId": 9, 1018 | "id": 170, 1019 | "title": "quisquam aliquam quia doloribus aut", 1020 | "completed": false 1021 | }, 1022 | { 1023 | "userId": 9, 1024 | "id": 171, 1025 | "title": "fugiat aut voluptatibus corrupti deleniti velit iste odio", 1026 | "completed": true 1027 | }, 1028 | { 1029 | "userId": 9, 1030 | "id": 172, 1031 | "title": "et provident amet rerum consectetur et voluptatum", 1032 | "completed": false 1033 | }, 1034 | { 1035 | "userId": 9, 1036 | "id": 173, 1037 | "title": "harum ad aperiam quis", 1038 | "completed": false 1039 | }, 1040 | { 1041 | "userId": 9, 1042 | "id": 174, 1043 | "title": "similique aut quo", 1044 | "completed": false 1045 | }, 1046 | { 1047 | "userId": 9, 1048 | "id": 175, 1049 | "title": "laudantium eius officia perferendis provident perspiciatis asperiores", 1050 | "completed": true 1051 | }, 1052 | { 1053 | "userId": 9, 1054 | "id": 176, 1055 | "title": "magni soluta corrupti ut maiores rem quidem", 1056 | "completed": false 1057 | }, 1058 | { 1059 | "userId": 9, 1060 | "id": 177, 1061 | "title": "et placeat temporibus voluptas est tempora quos quibusdam", 1062 | "completed": false 1063 | }, 1064 | { 1065 | "userId": 9, 1066 | "id": 178, 1067 | "title": "nesciunt itaque commodi tempore", 1068 | "completed": true 1069 | }, 1070 | { 1071 | "userId": 9, 1072 | "id": 179, 1073 | "title": "omnis consequuntur cupiditate impedit itaque ipsam quo", 1074 | "completed": true 1075 | }, 1076 | { 1077 | "userId": 9, 1078 | "id": 180, 1079 | "title": "debitis nisi et dolorem repellat et", 1080 | "completed": true 1081 | }, 1082 | { 1083 | "userId": 10, 1084 | "id": 181, 1085 | "title": "ut cupiditate sequi aliquam fuga maiores", 1086 | "completed": false 1087 | }, 1088 | { 1089 | "userId": 10, 1090 | "id": 182, 1091 | "title": "inventore saepe cumque et aut illum enim", 1092 | "completed": true 1093 | }, 1094 | { 1095 | "userId": 10, 1096 | "id": 183, 1097 | "title": "omnis nulla eum aliquam distinctio", 1098 | "completed": true 1099 | }, 1100 | { 1101 | "userId": 10, 1102 | "id": 184, 1103 | "title": "molestias modi perferendis perspiciatis", 1104 | "completed": false 1105 | }, 1106 | { 1107 | "userId": 10, 1108 | "id": 185, 1109 | "title": "voluptates dignissimos sed doloribus animi quaerat aut", 1110 | "completed": false 1111 | }, 1112 | { 1113 | "userId": 10, 1114 | "id": 186, 1115 | "title": "explicabo odio est et", 1116 | "completed": false 1117 | }, 1118 | { 1119 | "userId": 10, 1120 | "id": 187, 1121 | "title": "consequuntur animi possimus", 1122 | "completed": false 1123 | }, 1124 | { 1125 | "userId": 10, 1126 | "id": 188, 1127 | "title": "vel non beatae est", 1128 | "completed": true 1129 | }, 1130 | { 1131 | "userId": 10, 1132 | "id": 189, 1133 | "title": "culpa eius et voluptatem et", 1134 | "completed": true 1135 | }, 1136 | { 1137 | "userId": 10, 1138 | "id": 190, 1139 | "title": "accusamus sint iusto et voluptatem exercitationem", 1140 | "completed": true 1141 | }, 1142 | { 1143 | "userId": 10, 1144 | "id": 191, 1145 | "title": "temporibus atque distinctio omnis eius impedit tempore molestias pariatur", 1146 | "completed": true 1147 | }, 1148 | { 1149 | "userId": 10, 1150 | "id": 192, 1151 | "title": "ut quas possimus exercitationem sint voluptates", 1152 | "completed": false 1153 | }, 1154 | { 1155 | "userId": 10, 1156 | "id": 193, 1157 | "title": "rerum debitis voluptatem qui eveniet tempora distinctio a", 1158 | "completed": true 1159 | }, 1160 | { 1161 | "userId": 10, 1162 | "id": 194, 1163 | "title": "sed ut vero sit molestiae", 1164 | "completed": false 1165 | }, 1166 | { 1167 | "userId": 10, 1168 | "id": 195, 1169 | "title": "rerum ex veniam mollitia voluptatibus pariatur", 1170 | "completed": true 1171 | }, 1172 | { 1173 | "userId": 10, 1174 | "id": 196, 1175 | "title": "consequuntur aut ut fugit similique", 1176 | "completed": true 1177 | }, 1178 | { 1179 | "userId": 10, 1180 | "id": 197, 1181 | "title": "dignissimos quo nobis earum saepe", 1182 | "completed": true 1183 | }, 1184 | { 1185 | "userId": 10, 1186 | "id": 198, 1187 | "title": "quis eius est sint explicabo", 1188 | "completed": true 1189 | }, 1190 | { 1191 | "userId": 10, 1192 | "id": 199, 1193 | "title": "numquam repellendus a magnam", 1194 | "completed": true 1195 | }, 1196 | { 1197 | "userId": 10, 1198 | "id": 200, 1199 | "title": "ipsam aperiam voluptates qui", 1200 | "completed": false 1201 | } 1202 | ] -------------------------------------------------------------------------------- /75. Refactoring the code/jsplaceholder.py: -------------------------------------------------------------------------------- 1 | """ 2 | Refactoring code - changing your code so it doesn't change its behaviour 3 | (the things that it does). 4 | 5 | Why do it then? 6 | 7 | Do it so it's easier to maintain 8 | 9 | 10 | """ 11 | 12 | import requests 13 | import json 14 | 15 | response = requests.get("https://jsonplaceholder.typicode.com/todos") 16 | 17 | #tasks = json.loads(response.text) 18 | 19 | def count_completed_task_frequency(tasks): 20 | completedTasksFrequencyByUser = dict() 21 | for entry in tasks: 22 | if (entry["completed"] == True): 23 | try: 24 | completedTasksFrequencyByUser[entry["userId"]] += 1 25 | except KeyError: 26 | completedTasksFrequencyByUser[entry["userId"]] = 1 27 | return completedTasksFrequencyByUser 28 | 29 | def get_users_with_top_completed_tasks(completedTasksFrequencyByUser): 30 | usersIdWithMaxCompletedAmountOfTasks = [] 31 | maxAmountOfCompletedTasks = max(completedTasksFrequencyByUser.values()) 32 | for userId, numberOfCompletedTasks in completedTasksFrequencyByUser.items(): 33 | if (numberOfCompletedTasks == maxAmountOfCompletedTasks): 34 | usersIdWithMaxCompletedAmountOfTasks.append(userId) 35 | 36 | return usersIdWithMaxCompletedAmountOfTasks 37 | 38 | def get_keys_with_top_values(my_dict): 39 | return [key 40 | for key, value in my_dict.items() 41 | if (value == max(my_dict.values())) 42 | ] 43 | 44 | try: 45 | tasks = response.json() 46 | except json.decoder.JSONDecodeError: 47 | print("The content is not JSON") 48 | else: 49 | completedTasksFrequencyByUser = count_completed_task_frequency(tasks) 50 | usersIdWithMaxCompletedAmountOfTasks = get_users_with_top_completed_tasks(completedTasksFrequencyByUser) 51 | 52 | print("Cookies for:", usersIdWithMaxCompletedAmountOfTasks) 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /75. Refactoring the code/todos.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "userId": 1, 4 | "id": 1, 5 | "title": "delectus aut autem", 6 | "completed": false 7 | }, 8 | { 9 | "userId": 1, 10 | "id": 2, 11 | "title": "quis ut nam facilis et officia qui", 12 | "completed": false 13 | }, 14 | { 15 | "userId": 1, 16 | "id": 3, 17 | "title": "fugiat veniam minus", 18 | "completed": false 19 | }, 20 | { 21 | "userId": 1, 22 | "id": 4, 23 | "title": "et porro tempora", 24 | "completed": true 25 | }, 26 | { 27 | "userId": 1, 28 | "id": 5, 29 | "title": "laboriosam mollitia et enim quasi adipisci quia provident illum", 30 | "completed": false 31 | }, 32 | { 33 | "userId": 1, 34 | "id": 6, 35 | "title": "qui ullam ratione quibusdam voluptatem quia omnis", 36 | "completed": false 37 | }, 38 | { 39 | "userId": 1, 40 | "id": 7, 41 | "title": "illo expedita consequatur quia in", 42 | "completed": false 43 | }, 44 | { 45 | "userId": 1, 46 | "id": 8, 47 | "title": "quo adipisci enim quam ut ab", 48 | "completed": true 49 | }, 50 | { 51 | "userId": 1, 52 | "id": 9, 53 | "title": "molestiae perspiciatis ipsa", 54 | "completed": false 55 | }, 56 | { 57 | "userId": 1, 58 | "id": 10, 59 | "title": "illo est ratione doloremque quia maiores aut", 60 | "completed": true 61 | }, 62 | { 63 | "userId": 1, 64 | "id": 11, 65 | "title": "vero rerum temporibus dolor", 66 | "completed": true 67 | }, 68 | { 69 | "userId": 1, 70 | "id": 12, 71 | "title": "ipsa repellendus fugit nisi", 72 | "completed": true 73 | }, 74 | { 75 | "userId": 1, 76 | "id": 13, 77 | "title": "et doloremque nulla", 78 | "completed": false 79 | }, 80 | { 81 | "userId": 1, 82 | "id": 14, 83 | "title": "repellendus sunt dolores architecto voluptatum", 84 | "completed": true 85 | }, 86 | { 87 | "userId": 1, 88 | "id": 15, 89 | "title": "ab voluptatum amet voluptas", 90 | "completed": true 91 | }, 92 | { 93 | "userId": 1, 94 | "id": 16, 95 | "title": "accusamus eos facilis sint et aut voluptatem", 96 | "completed": true 97 | }, 98 | { 99 | "userId": 1, 100 | "id": 17, 101 | "title": "quo laboriosam deleniti aut qui", 102 | "completed": true 103 | }, 104 | { 105 | "userId": 1, 106 | "id": 18, 107 | "title": "dolorum est consequatur ea mollitia in culpa", 108 | "completed": false 109 | }, 110 | { 111 | "userId": 1, 112 | "id": 19, 113 | "title": "molestiae ipsa aut voluptatibus pariatur dolor nihil", 114 | "completed": true 115 | }, 116 | { 117 | "userId": 1, 118 | "id": 20, 119 | "title": "ullam nobis libero sapiente ad optio sint", 120 | "completed": true 121 | }, 122 | { 123 | "userId": 2, 124 | "id": 21, 125 | "title": "suscipit repellat esse quibusdam voluptatem incidunt", 126 | "completed": false 127 | }, 128 | { 129 | "userId": 2, 130 | "id": 22, 131 | "title": "distinctio vitae autem nihil ut molestias quo", 132 | "completed": true 133 | }, 134 | { 135 | "userId": 2, 136 | "id": 23, 137 | "title": "et itaque necessitatibus maxime molestiae qui quas velit", 138 | "completed": false 139 | }, 140 | { 141 | "userId": 2, 142 | "id": 24, 143 | "title": "adipisci non ad dicta qui amet quaerat doloribus ea", 144 | "completed": false 145 | }, 146 | { 147 | "userId": 2, 148 | "id": 25, 149 | "title": "voluptas quo tenetur perspiciatis explicabo natus", 150 | "completed": true 151 | }, 152 | { 153 | "userId": 2, 154 | "id": 26, 155 | "title": "aliquam aut quasi", 156 | "completed": true 157 | }, 158 | { 159 | "userId": 2, 160 | "id": 27, 161 | "title": "veritatis pariatur delectus", 162 | "completed": true 163 | }, 164 | { 165 | "userId": 2, 166 | "id": 28, 167 | "title": "nesciunt totam sit blanditiis sit", 168 | "completed": false 169 | }, 170 | { 171 | "userId": 2, 172 | "id": 29, 173 | "title": "laborum aut in quam", 174 | "completed": false 175 | }, 176 | { 177 | "userId": 2, 178 | "id": 30, 179 | "title": "nemo perspiciatis repellat ut dolor libero commodi blanditiis omnis", 180 | "completed": true 181 | }, 182 | { 183 | "userId": 2, 184 | "id": 31, 185 | "title": "repudiandae totam in est sint facere fuga", 186 | "completed": false 187 | }, 188 | { 189 | "userId": 2, 190 | "id": 32, 191 | "title": "earum doloribus ea doloremque quis", 192 | "completed": false 193 | }, 194 | { 195 | "userId": 2, 196 | "id": 33, 197 | "title": "sint sit aut vero", 198 | "completed": false 199 | }, 200 | { 201 | "userId": 2, 202 | "id": 34, 203 | "title": "porro aut necessitatibus eaque distinctio", 204 | "completed": false 205 | }, 206 | { 207 | "userId": 2, 208 | "id": 35, 209 | "title": "repellendus veritatis molestias dicta incidunt", 210 | "completed": true 211 | }, 212 | { 213 | "userId": 2, 214 | "id": 36, 215 | "title": "excepturi deleniti adipisci voluptatem et neque optio illum ad", 216 | "completed": true 217 | }, 218 | { 219 | "userId": 2, 220 | "id": 37, 221 | "title": "sunt cum tempora", 222 | "completed": false 223 | }, 224 | { 225 | "userId": 2, 226 | "id": 38, 227 | "title": "totam quia non", 228 | "completed": false 229 | }, 230 | { 231 | "userId": 2, 232 | "id": 39, 233 | "title": "doloremque quibusdam asperiores libero corrupti illum qui omnis", 234 | "completed": false 235 | }, 236 | { 237 | "userId": 2, 238 | "id": 40, 239 | "title": "totam atque quo nesciunt", 240 | "completed": true 241 | }, 242 | { 243 | "userId": 3, 244 | "id": 41, 245 | "title": "aliquid amet impedit consequatur aspernatur placeat eaque fugiat suscipit", 246 | "completed": false 247 | }, 248 | { 249 | "userId": 3, 250 | "id": 42, 251 | "title": "rerum perferendis error quia ut eveniet", 252 | "completed": false 253 | }, 254 | { 255 | "userId": 3, 256 | "id": 43, 257 | "title": "tempore ut sint quis recusandae", 258 | "completed": true 259 | }, 260 | { 261 | "userId": 3, 262 | "id": 44, 263 | "title": "cum debitis quis accusamus doloremque ipsa natus sapiente omnis", 264 | "completed": true 265 | }, 266 | { 267 | "userId": 3, 268 | "id": 45, 269 | "title": "velit soluta adipisci molestias reiciendis harum", 270 | "completed": false 271 | }, 272 | { 273 | "userId": 3, 274 | "id": 46, 275 | "title": "vel voluptatem repellat nihil placeat corporis", 276 | "completed": false 277 | }, 278 | { 279 | "userId": 3, 280 | "id": 47, 281 | "title": "nam qui rerum fugiat accusamus", 282 | "completed": false 283 | }, 284 | { 285 | "userId": 3, 286 | "id": 48, 287 | "title": "sit reprehenderit omnis quia", 288 | "completed": false 289 | }, 290 | { 291 | "userId": 3, 292 | "id": 49, 293 | "title": "ut necessitatibus aut maiores debitis officia blanditiis velit et", 294 | "completed": false 295 | }, 296 | { 297 | "userId": 3, 298 | "id": 50, 299 | "title": "cupiditate necessitatibus ullam aut quis dolor voluptate", 300 | "completed": true 301 | }, 302 | { 303 | "userId": 3, 304 | "id": 51, 305 | "title": "distinctio exercitationem ab doloribus", 306 | "completed": false 307 | }, 308 | { 309 | "userId": 3, 310 | "id": 52, 311 | "title": "nesciunt dolorum quis recusandae ad pariatur ratione", 312 | "completed": false 313 | }, 314 | { 315 | "userId": 3, 316 | "id": 53, 317 | "title": "qui labore est occaecati recusandae aliquid quam", 318 | "completed": false 319 | }, 320 | { 321 | "userId": 3, 322 | "id": 54, 323 | "title": "quis et est ut voluptate quam dolor", 324 | "completed": true 325 | }, 326 | { 327 | "userId": 3, 328 | "id": 55, 329 | "title": "voluptatum omnis minima qui occaecati provident nulla voluptatem ratione", 330 | "completed": true 331 | }, 332 | { 333 | "userId": 3, 334 | "id": 56, 335 | "title": "deleniti ea temporibus enim", 336 | "completed": true 337 | }, 338 | { 339 | "userId": 3, 340 | "id": 57, 341 | "title": "pariatur et magnam ea doloribus similique voluptatem rerum quia", 342 | "completed": false 343 | }, 344 | { 345 | "userId": 3, 346 | "id": 58, 347 | "title": "est dicta totam qui explicabo doloribus qui dignissimos", 348 | "completed": false 349 | }, 350 | { 351 | "userId": 3, 352 | "id": 59, 353 | "title": "perspiciatis velit id laborum placeat iusto et aliquam odio", 354 | "completed": false 355 | }, 356 | { 357 | "userId": 3, 358 | "id": 60, 359 | "title": "et sequi qui architecto ut adipisci", 360 | "completed": true 361 | }, 362 | { 363 | "userId": 4, 364 | "id": 61, 365 | "title": "odit optio omnis qui sunt", 366 | "completed": true 367 | }, 368 | { 369 | "userId": 4, 370 | "id": 62, 371 | "title": "et placeat et tempore aspernatur sint numquam", 372 | "completed": false 373 | }, 374 | { 375 | "userId": 4, 376 | "id": 63, 377 | "title": "doloremque aut dolores quidem fuga qui nulla", 378 | "completed": true 379 | }, 380 | { 381 | "userId": 4, 382 | "id": 64, 383 | "title": "voluptas consequatur qui ut quia magnam nemo esse", 384 | "completed": false 385 | }, 386 | { 387 | "userId": 4, 388 | "id": 65, 389 | "title": "fugiat pariatur ratione ut asperiores necessitatibus magni", 390 | "completed": false 391 | }, 392 | { 393 | "userId": 4, 394 | "id": 66, 395 | "title": "rerum eum molestias autem voluptatum sit optio", 396 | "completed": false 397 | }, 398 | { 399 | "userId": 4, 400 | "id": 67, 401 | "title": "quia voluptatibus voluptatem quos similique maiores repellat", 402 | "completed": false 403 | }, 404 | { 405 | "userId": 4, 406 | "id": 68, 407 | "title": "aut id perspiciatis voluptatem iusto", 408 | "completed": false 409 | }, 410 | { 411 | "userId": 4, 412 | "id": 69, 413 | "title": "doloribus sint dolorum ab adipisci itaque dignissimos aliquam suscipit", 414 | "completed": false 415 | }, 416 | { 417 | "userId": 4, 418 | "id": 70, 419 | "title": "ut sequi accusantium et mollitia delectus sunt", 420 | "completed": false 421 | }, 422 | { 423 | "userId": 4, 424 | "id": 71, 425 | "title": "aut velit saepe ullam", 426 | "completed": false 427 | }, 428 | { 429 | "userId": 4, 430 | "id": 72, 431 | "title": "praesentium facilis facere quis harum voluptatibus voluptatem eum", 432 | "completed": false 433 | }, 434 | { 435 | "userId": 4, 436 | "id": 73, 437 | "title": "sint amet quia totam corporis qui exercitationem commodi", 438 | "completed": true 439 | }, 440 | { 441 | "userId": 4, 442 | "id": 74, 443 | "title": "expedita tempore nobis eveniet laborum maiores", 444 | "completed": false 445 | }, 446 | { 447 | "userId": 4, 448 | "id": 75, 449 | "title": "occaecati adipisci est possimus totam", 450 | "completed": false 451 | }, 452 | { 453 | "userId": 4, 454 | "id": 76, 455 | "title": "sequi dolorem sed", 456 | "completed": true 457 | }, 458 | { 459 | "userId": 4, 460 | "id": 77, 461 | "title": "maiores aut nesciunt delectus exercitationem vel assumenda eligendi at", 462 | "completed": false 463 | }, 464 | { 465 | "userId": 4, 466 | "id": 78, 467 | "title": "reiciendis est magnam amet nemo iste recusandae impedit quaerat", 468 | "completed": false 469 | }, 470 | { 471 | "userId": 4, 472 | "id": 79, 473 | "title": "eum ipsa maxime ut", 474 | "completed": true 475 | }, 476 | { 477 | "userId": 4, 478 | "id": 80, 479 | "title": "tempore molestias dolores rerum sequi voluptates ipsum consequatur", 480 | "completed": true 481 | }, 482 | { 483 | "userId": 5, 484 | "id": 81, 485 | "title": "suscipit qui totam", 486 | "completed": true 487 | }, 488 | { 489 | "userId": 5, 490 | "id": 82, 491 | "title": "voluptates eum voluptas et dicta", 492 | "completed": false 493 | }, 494 | { 495 | "userId": 5, 496 | "id": 83, 497 | "title": "quidem at rerum quis ex aut sit quam", 498 | "completed": true 499 | }, 500 | { 501 | "userId": 5, 502 | "id": 84, 503 | "title": "sunt veritatis ut voluptate", 504 | "completed": false 505 | }, 506 | { 507 | "userId": 5, 508 | "id": 85, 509 | "title": "et quia ad iste a", 510 | "completed": true 511 | }, 512 | { 513 | "userId": 5, 514 | "id": 86, 515 | "title": "incidunt ut saepe autem", 516 | "completed": true 517 | }, 518 | { 519 | "userId": 5, 520 | "id": 87, 521 | "title": "laudantium quae eligendi consequatur quia et vero autem", 522 | "completed": true 523 | }, 524 | { 525 | "userId": 5, 526 | "id": 88, 527 | "title": "vitae aut excepturi laboriosam sint aliquam et et accusantium", 528 | "completed": false 529 | }, 530 | { 531 | "userId": 5, 532 | "id": 89, 533 | "title": "sequi ut omnis et", 534 | "completed": true 535 | }, 536 | { 537 | "userId": 5, 538 | "id": 90, 539 | "title": "molestiae nisi accusantium tenetur dolorem et", 540 | "completed": true 541 | }, 542 | { 543 | "userId": 5, 544 | "id": 91, 545 | "title": "nulla quis consequatur saepe qui id expedita", 546 | "completed": true 547 | }, 548 | { 549 | "userId": 5, 550 | "id": 92, 551 | "title": "in omnis laboriosam", 552 | "completed": true 553 | }, 554 | { 555 | "userId": 5, 556 | "id": 93, 557 | "title": "odio iure consequatur molestiae quibusdam necessitatibus quia sint", 558 | "completed": true 559 | }, 560 | { 561 | "userId": 5, 562 | "id": 94, 563 | "title": "facilis modi saepe mollitia", 564 | "completed": false 565 | }, 566 | { 567 | "userId": 5, 568 | "id": 95, 569 | "title": "vel nihil et molestiae iusto assumenda nemo quo ut", 570 | "completed": true 571 | }, 572 | { 573 | "userId": 5, 574 | "id": 96, 575 | "title": "nobis suscipit ducimus enim asperiores voluptas", 576 | "completed": false 577 | }, 578 | { 579 | "userId": 5, 580 | "id": 97, 581 | "title": "dolorum laboriosam eos qui iure aliquam", 582 | "completed": false 583 | }, 584 | { 585 | "userId": 5, 586 | "id": 98, 587 | "title": "debitis accusantium ut quo facilis nihil quis sapiente necessitatibus", 588 | "completed": true 589 | }, 590 | { 591 | "userId": 5, 592 | "id": 99, 593 | "title": "neque voluptates ratione", 594 | "completed": false 595 | }, 596 | { 597 | "userId": 5, 598 | "id": 100, 599 | "title": "excepturi a et neque qui expedita vel voluptate", 600 | "completed": false 601 | }, 602 | { 603 | "userId": 6, 604 | "id": 101, 605 | "title": "explicabo enim cumque porro aperiam occaecati minima", 606 | "completed": false 607 | }, 608 | { 609 | "userId": 6, 610 | "id": 102, 611 | "title": "sed ab consequatur", 612 | "completed": false 613 | }, 614 | { 615 | "userId": 6, 616 | "id": 103, 617 | "title": "non sunt delectus illo nulla tenetur enim omnis", 618 | "completed": false 619 | }, 620 | { 621 | "userId": 6, 622 | "id": 104, 623 | "title": "excepturi non laudantium quo", 624 | "completed": false 625 | }, 626 | { 627 | "userId": 6, 628 | "id": 105, 629 | "title": "totam quia dolorem et illum repellat voluptas optio", 630 | "completed": true 631 | }, 632 | { 633 | "userId": 6, 634 | "id": 106, 635 | "title": "ad illo quis voluptatem temporibus", 636 | "completed": true 637 | }, 638 | { 639 | "userId": 6, 640 | "id": 107, 641 | "title": "praesentium facilis omnis laudantium fugit ad iusto nihil nesciunt", 642 | "completed": false 643 | }, 644 | { 645 | "userId": 6, 646 | "id": 108, 647 | "title": "a eos eaque nihil et exercitationem incidunt delectus", 648 | "completed": true 649 | }, 650 | { 651 | "userId": 6, 652 | "id": 109, 653 | "title": "autem temporibus harum quisquam in culpa", 654 | "completed": true 655 | }, 656 | { 657 | "userId": 6, 658 | "id": 110, 659 | "title": "aut aut ea corporis", 660 | "completed": true 661 | }, 662 | { 663 | "userId": 6, 664 | "id": 111, 665 | "title": "magni accusantium labore et id quis provident", 666 | "completed": false 667 | }, 668 | { 669 | "userId": 6, 670 | "id": 112, 671 | "title": "consectetur impedit quisquam qui deserunt non rerum consequuntur eius", 672 | "completed": false 673 | }, 674 | { 675 | "userId": 6, 676 | "id": 113, 677 | "title": "quia atque aliquam sunt impedit voluptatum rerum assumenda nisi", 678 | "completed": false 679 | }, 680 | { 681 | "userId": 6, 682 | "id": 114, 683 | "title": "cupiditate quos possimus corporis quisquam exercitationem beatae", 684 | "completed": false 685 | }, 686 | { 687 | "userId": 6, 688 | "id": 115, 689 | "title": "sed et ea eum", 690 | "completed": false 691 | }, 692 | { 693 | "userId": 6, 694 | "id": 116, 695 | "title": "ipsa dolores vel facilis ut", 696 | "completed": true 697 | }, 698 | { 699 | "userId": 6, 700 | "id": 117, 701 | "title": "sequi quae est et qui qui eveniet asperiores", 702 | "completed": false 703 | }, 704 | { 705 | "userId": 6, 706 | "id": 118, 707 | "title": "quia modi consequatur vero fugiat", 708 | "completed": false 709 | }, 710 | { 711 | "userId": 6, 712 | "id": 119, 713 | "title": "corporis ducimus ea perspiciatis iste", 714 | "completed": false 715 | }, 716 | { 717 | "userId": 6, 718 | "id": 120, 719 | "title": "dolorem laboriosam vel voluptas et aliquam quasi", 720 | "completed": false 721 | }, 722 | { 723 | "userId": 7, 724 | "id": 121, 725 | "title": "inventore aut nihil minima laudantium hic qui omnis", 726 | "completed": true 727 | }, 728 | { 729 | "userId": 7, 730 | "id": 122, 731 | "title": "provident aut nobis culpa", 732 | "completed": true 733 | }, 734 | { 735 | "userId": 7, 736 | "id": 123, 737 | "title": "esse et quis iste est earum aut impedit", 738 | "completed": false 739 | }, 740 | { 741 | "userId": 7, 742 | "id": 124, 743 | "title": "qui consectetur id", 744 | "completed": false 745 | }, 746 | { 747 | "userId": 7, 748 | "id": 125, 749 | "title": "aut quasi autem iste tempore illum possimus", 750 | "completed": false 751 | }, 752 | { 753 | "userId": 7, 754 | "id": 126, 755 | "title": "ut asperiores perspiciatis veniam ipsum rerum saepe", 756 | "completed": true 757 | }, 758 | { 759 | "userId": 7, 760 | "id": 127, 761 | "title": "voluptatem libero consectetur rerum ut", 762 | "completed": true 763 | }, 764 | { 765 | "userId": 7, 766 | "id": 128, 767 | "title": "eius omnis est qui voluptatem autem", 768 | "completed": false 769 | }, 770 | { 771 | "userId": 7, 772 | "id": 129, 773 | "title": "rerum culpa quis harum", 774 | "completed": false 775 | }, 776 | { 777 | "userId": 7, 778 | "id": 130, 779 | "title": "nulla aliquid eveniet harum laborum libero alias ut unde", 780 | "completed": true 781 | }, 782 | { 783 | "userId": 7, 784 | "id": 131, 785 | "title": "qui ea incidunt quis", 786 | "completed": false 787 | }, 788 | { 789 | "userId": 7, 790 | "id": 132, 791 | "title": "qui molestiae voluptatibus velit iure harum quisquam", 792 | "completed": true 793 | }, 794 | { 795 | "userId": 7, 796 | "id": 133, 797 | "title": "et labore eos enim rerum consequatur sunt", 798 | "completed": true 799 | }, 800 | { 801 | "userId": 7, 802 | "id": 134, 803 | "title": "molestiae doloribus et laborum quod ea", 804 | "completed": false 805 | }, 806 | { 807 | "userId": 7, 808 | "id": 135, 809 | "title": "facere ipsa nam eum voluptates reiciendis vero qui", 810 | "completed": false 811 | }, 812 | { 813 | "userId": 7, 814 | "id": 136, 815 | "title": "asperiores illo tempora fuga sed ut quasi adipisci", 816 | "completed": false 817 | }, 818 | { 819 | "userId": 7, 820 | "id": 137, 821 | "title": "qui sit non", 822 | "completed": false 823 | }, 824 | { 825 | "userId": 7, 826 | "id": 138, 827 | "title": "placeat minima consequatur rem qui ut", 828 | "completed": true 829 | }, 830 | { 831 | "userId": 7, 832 | "id": 139, 833 | "title": "consequatur doloribus id possimus voluptas a voluptatem", 834 | "completed": false 835 | }, 836 | { 837 | "userId": 7, 838 | "id": 140, 839 | "title": "aut consectetur in blanditiis deserunt quia sed laboriosam", 840 | "completed": true 841 | }, 842 | { 843 | "userId": 8, 844 | "id": 141, 845 | "title": "explicabo consectetur debitis voluptates quas quae culpa rerum non", 846 | "completed": true 847 | }, 848 | { 849 | "userId": 8, 850 | "id": 142, 851 | "title": "maiores accusantium architecto necessitatibus reiciendis ea aut", 852 | "completed": true 853 | }, 854 | { 855 | "userId": 8, 856 | "id": 143, 857 | "title": "eum non recusandae cupiditate animi", 858 | "completed": false 859 | }, 860 | { 861 | "userId": 8, 862 | "id": 144, 863 | "title": "ut eum exercitationem sint", 864 | "completed": false 865 | }, 866 | { 867 | "userId": 8, 868 | "id": 145, 869 | "title": "beatae qui ullam incidunt voluptatem non nisi aliquam", 870 | "completed": false 871 | }, 872 | { 873 | "userId": 8, 874 | "id": 146, 875 | "title": "molestiae suscipit ratione nihil odio libero impedit vero totam", 876 | "completed": true 877 | }, 878 | { 879 | "userId": 8, 880 | "id": 147, 881 | "title": "eum itaque quod reprehenderit et facilis dolor autem ut", 882 | "completed": true 883 | }, 884 | { 885 | "userId": 8, 886 | "id": 148, 887 | "title": "esse quas et quo quasi exercitationem", 888 | "completed": false 889 | }, 890 | { 891 | "userId": 8, 892 | "id": 149, 893 | "title": "animi voluptas quod perferendis est", 894 | "completed": false 895 | }, 896 | { 897 | "userId": 8, 898 | "id": 150, 899 | "title": "eos amet tempore laudantium fugit a", 900 | "completed": false 901 | }, 902 | { 903 | "userId": 8, 904 | "id": 151, 905 | "title": "accusamus adipisci dicta qui quo ea explicabo sed vero", 906 | "completed": true 907 | }, 908 | { 909 | "userId": 8, 910 | "id": 152, 911 | "title": "odit eligendi recusandae doloremque cumque non", 912 | "completed": false 913 | }, 914 | { 915 | "userId": 8, 916 | "id": 153, 917 | "title": "ea aperiam consequatur qui repellat eos", 918 | "completed": false 919 | }, 920 | { 921 | "userId": 8, 922 | "id": 154, 923 | "title": "rerum non ex sapiente", 924 | "completed": true 925 | }, 926 | { 927 | "userId": 8, 928 | "id": 155, 929 | "title": "voluptatem nobis consequatur et assumenda magnam", 930 | "completed": true 931 | }, 932 | { 933 | "userId": 8, 934 | "id": 156, 935 | "title": "nam quia quia nulla repellat assumenda quibusdam sit nobis", 936 | "completed": true 937 | }, 938 | { 939 | "userId": 8, 940 | "id": 157, 941 | "title": "dolorem veniam quisquam deserunt repellendus", 942 | "completed": true 943 | }, 944 | { 945 | "userId": 8, 946 | "id": 158, 947 | "title": "debitis vitae delectus et harum accusamus aut deleniti a", 948 | "completed": true 949 | }, 950 | { 951 | "userId": 8, 952 | "id": 159, 953 | "title": "debitis adipisci quibusdam aliquam sed dolore ea praesentium nobis", 954 | "completed": true 955 | }, 956 | { 957 | "userId": 8, 958 | "id": 160, 959 | "title": "et praesentium aliquam est", 960 | "completed": false 961 | }, 962 | { 963 | "userId": 9, 964 | "id": 161, 965 | "title": "ex hic consequuntur earum omnis alias ut occaecati culpa", 966 | "completed": true 967 | }, 968 | { 969 | "userId": 9, 970 | "id": 162, 971 | "title": "omnis laboriosam molestias animi sunt dolore", 972 | "completed": true 973 | }, 974 | { 975 | "userId": 9, 976 | "id": 163, 977 | "title": "natus corrupti maxime laudantium et voluptatem laboriosam odit", 978 | "completed": false 979 | }, 980 | { 981 | "userId": 9, 982 | "id": 164, 983 | "title": "reprehenderit quos aut aut consequatur est sed", 984 | "completed": false 985 | }, 986 | { 987 | "userId": 9, 988 | "id": 165, 989 | "title": "fugiat perferendis sed aut quidem", 990 | "completed": false 991 | }, 992 | { 993 | "userId": 9, 994 | "id": 166, 995 | "title": "quos quo possimus suscipit minima ut", 996 | "completed": false 997 | }, 998 | { 999 | "userId": 9, 1000 | "id": 167, 1001 | "title": "et quis minus quo a asperiores molestiae", 1002 | "completed": false 1003 | }, 1004 | { 1005 | "userId": 9, 1006 | "id": 168, 1007 | "title": "recusandae quia qui sunt libero", 1008 | "completed": false 1009 | }, 1010 | { 1011 | "userId": 9, 1012 | "id": 169, 1013 | "title": "ea odio perferendis officiis", 1014 | "completed": true 1015 | }, 1016 | { 1017 | "userId": 9, 1018 | "id": 170, 1019 | "title": "quisquam aliquam quia doloribus aut", 1020 | "completed": false 1021 | }, 1022 | { 1023 | "userId": 9, 1024 | "id": 171, 1025 | "title": "fugiat aut voluptatibus corrupti deleniti velit iste odio", 1026 | "completed": true 1027 | }, 1028 | { 1029 | "userId": 9, 1030 | "id": 172, 1031 | "title": "et provident amet rerum consectetur et voluptatum", 1032 | "completed": false 1033 | }, 1034 | { 1035 | "userId": 9, 1036 | "id": 173, 1037 | "title": "harum ad aperiam quis", 1038 | "completed": false 1039 | }, 1040 | { 1041 | "userId": 9, 1042 | "id": 174, 1043 | "title": "similique aut quo", 1044 | "completed": false 1045 | }, 1046 | { 1047 | "userId": 9, 1048 | "id": 175, 1049 | "title": "laudantium eius officia perferendis provident perspiciatis asperiores", 1050 | "completed": true 1051 | }, 1052 | { 1053 | "userId": 9, 1054 | "id": 176, 1055 | "title": "magni soluta corrupti ut maiores rem quidem", 1056 | "completed": false 1057 | }, 1058 | { 1059 | "userId": 9, 1060 | "id": 177, 1061 | "title": "et placeat temporibus voluptas est tempora quos quibusdam", 1062 | "completed": false 1063 | }, 1064 | { 1065 | "userId": 9, 1066 | "id": 178, 1067 | "title": "nesciunt itaque commodi tempore", 1068 | "completed": true 1069 | }, 1070 | { 1071 | "userId": 9, 1072 | "id": 179, 1073 | "title": "omnis consequuntur cupiditate impedit itaque ipsam quo", 1074 | "completed": true 1075 | }, 1076 | { 1077 | "userId": 9, 1078 | "id": 180, 1079 | "title": "debitis nisi et dolorem repellat et", 1080 | "completed": true 1081 | }, 1082 | { 1083 | "userId": 10, 1084 | "id": 181, 1085 | "title": "ut cupiditate sequi aliquam fuga maiores", 1086 | "completed": false 1087 | }, 1088 | { 1089 | "userId": 10, 1090 | "id": 182, 1091 | "title": "inventore saepe cumque et aut illum enim", 1092 | "completed": true 1093 | }, 1094 | { 1095 | "userId": 10, 1096 | "id": 183, 1097 | "title": "omnis nulla eum aliquam distinctio", 1098 | "completed": true 1099 | }, 1100 | { 1101 | "userId": 10, 1102 | "id": 184, 1103 | "title": "molestias modi perferendis perspiciatis", 1104 | "completed": false 1105 | }, 1106 | { 1107 | "userId": 10, 1108 | "id": 185, 1109 | "title": "voluptates dignissimos sed doloribus animi quaerat aut", 1110 | "completed": false 1111 | }, 1112 | { 1113 | "userId": 10, 1114 | "id": 186, 1115 | "title": "explicabo odio est et", 1116 | "completed": false 1117 | }, 1118 | { 1119 | "userId": 10, 1120 | "id": 187, 1121 | "title": "consequuntur animi possimus", 1122 | "completed": false 1123 | }, 1124 | { 1125 | "userId": 10, 1126 | "id": 188, 1127 | "title": "vel non beatae est", 1128 | "completed": true 1129 | }, 1130 | { 1131 | "userId": 10, 1132 | "id": 189, 1133 | "title": "culpa eius et voluptatem et", 1134 | "completed": true 1135 | }, 1136 | { 1137 | "userId": 10, 1138 | "id": 190, 1139 | "title": "accusamus sint iusto et voluptatem exercitationem", 1140 | "completed": true 1141 | }, 1142 | { 1143 | "userId": 10, 1144 | "id": 191, 1145 | "title": "temporibus atque distinctio omnis eius impedit tempore molestias pariatur", 1146 | "completed": true 1147 | }, 1148 | { 1149 | "userId": 10, 1150 | "id": 192, 1151 | "title": "ut quas possimus exercitationem sint voluptates", 1152 | "completed": false 1153 | }, 1154 | { 1155 | "userId": 10, 1156 | "id": 193, 1157 | "title": "rerum debitis voluptatem qui eveniet tempora distinctio a", 1158 | "completed": true 1159 | }, 1160 | { 1161 | "userId": 10, 1162 | "id": 194, 1163 | "title": "sed ut vero sit molestiae", 1164 | "completed": false 1165 | }, 1166 | { 1167 | "userId": 10, 1168 | "id": 195, 1169 | "title": "rerum ex veniam mollitia voluptatibus pariatur", 1170 | "completed": true 1171 | }, 1172 | { 1173 | "userId": 10, 1174 | "id": 196, 1175 | "title": "consequuntur aut ut fugit similique", 1176 | "completed": true 1177 | }, 1178 | { 1179 | "userId": 10, 1180 | "id": 197, 1181 | "title": "dignissimos quo nobis earum saepe", 1182 | "completed": true 1183 | }, 1184 | { 1185 | "userId": 10, 1186 | "id": 198, 1187 | "title": "quis eius est sint explicabo", 1188 | "completed": true 1189 | }, 1190 | { 1191 | "userId": 10, 1192 | "id": 199, 1193 | "title": "numquam repellendus a magnam", 1194 | "completed": true 1195 | }, 1196 | { 1197 | "userId": 10, 1198 | "id": 200, 1199 | "title": "ipsam aperiam voluptates qui", 1200 | "completed": false 1201 | } 1202 | ] -------------------------------------------------------------------------------- /76. Solution 1 - Retrieving a few users from server/jsplaceholder.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | response = requests.get("https://jsonplaceholder.typicode.com/todos") 5 | 6 | def count_completed_task_frequency(tasks): 7 | completedTasksFrequencyByUser = dict() 8 | for entry in tasks: 9 | if (entry["completed"] == True): 10 | try: 11 | completedTasksFrequencyByUser[entry["userId"]] += 1 12 | except KeyError: 13 | completedTasksFrequencyByUser[entry["userId"]] = 1 14 | return completedTasksFrequencyByUser 15 | 16 | def get_users_with_top_completed_tasks(completedTasksFrequencyByUser): 17 | usersIdWithMaxCompletedAmountOfTasks = [] 18 | maxAmountOfCompletedTasks = max(completedTasksFrequencyByUser.values()) 19 | for userId, numberOfCompletedTasks in completedTasksFrequencyByUser.items(): 20 | if (numberOfCompletedTasks == maxAmountOfCompletedTasks): 21 | usersIdWithMaxCompletedAmountOfTasks.append(userId) 22 | 23 | return usersIdWithMaxCompletedAmountOfTasks 24 | 25 | try: 26 | tasks = response.json() 27 | except json.decoder.JSONDecodeError: 28 | print("The content is not JSON") 29 | else: 30 | completedTasksFrequencyByUser = count_completed_task_frequency(tasks) 31 | usersIdWithMaxCompletedAmountOfTasks = get_users_with_top_completed_tasks(completedTasksFrequencyByUser) 32 | 33 | 34 | 35 | 36 | #solution 1 37 | 38 | r = requests.get("https://jsonplaceholder.typicode.com/users") 39 | users = r.json() 40 | 41 | for user in users: 42 | if (user["id"] in usersIdWithMaxCompletedAmountOfTasks): 43 | print("Cookie for:", user["name"]) 44 | usersIdWithMaxCompletedAmountOfTasks.remove(user["id"]) 45 | -------------------------------------------------------------------------------- /76. Solution 1 - Retrieving a few users from server/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "name": "Leanne Graham", 5 | "username": "Bret", 6 | "email": "Sincere@april.biz", 7 | "address": { 8 | "street": "Kulas Light", 9 | "suite": "Apt. 556", 10 | "city": "Gwenborough", 11 | "zipcode": "92998-3874", 12 | "geo": { 13 | "lat": "-37.3159", 14 | "lng": "81.1496" 15 | } 16 | }, 17 | "phone": "1-770-736-8031 x56442", 18 | "website": "hildegard.org", 19 | "company": { 20 | "name": "Romaguera-Crona", 21 | "catchPhrase": "Multi-layered client-server neural-net", 22 | "bs": "harness real-time e-markets" 23 | } 24 | }, 25 | { 26 | "id": 2, 27 | "name": "Ervin Howell", 28 | "username": "Antonette", 29 | "email": "Shanna@melissa.tv", 30 | "address": { 31 | "street": "Victor Plains", 32 | "suite": "Suite 879", 33 | "city": "Wisokyburgh", 34 | "zipcode": "90566-7771", 35 | "geo": { 36 | "lat": "-43.9509", 37 | "lng": "-34.4618" 38 | } 39 | }, 40 | "phone": "010-692-6593 x09125", 41 | "website": "anastasia.net", 42 | "company": { 43 | "name": "Deckow-Crist", 44 | "catchPhrase": "Proactive didactic contingency", 45 | "bs": "synergize scalable supply-chains" 46 | } 47 | }, 48 | { 49 | "id": 3, 50 | "name": "Clementine Bauch", 51 | "username": "Samantha", 52 | "email": "Nathan@yesenia.net", 53 | "address": { 54 | "street": "Douglas Extension", 55 | "suite": "Suite 847", 56 | "city": "McKenziehaven", 57 | "zipcode": "59590-4157", 58 | "geo": { 59 | "lat": "-68.6102", 60 | "lng": "-47.0653" 61 | } 62 | }, 63 | "phone": "1-463-123-4447", 64 | "website": "ramiro.info", 65 | "company": { 66 | "name": "Romaguera-Jacobson", 67 | "catchPhrase": "Face to face bifurcated interface", 68 | "bs": "e-enable strategic applications" 69 | } 70 | }, 71 | { 72 | "id": 4, 73 | "name": "Patricia Lebsack", 74 | "username": "Karianne", 75 | "email": "Julianne.OConner@kory.org", 76 | "address": { 77 | "street": "Hoeger Mall", 78 | "suite": "Apt. 692", 79 | "city": "South Elvis", 80 | "zipcode": "53919-4257", 81 | "geo": { 82 | "lat": "29.4572", 83 | "lng": "-164.2990" 84 | } 85 | }, 86 | "phone": "493-170-9623 x156", 87 | "website": "kale.biz", 88 | "company": { 89 | "name": "Robel-Corkery", 90 | "catchPhrase": "Multi-tiered zero tolerance productivity", 91 | "bs": "transition cutting-edge web services" 92 | } 93 | }, 94 | { 95 | "id": 5, 96 | "name": "Chelsey Dietrich", 97 | "username": "Kamren", 98 | "email": "Lucio_Hettinger@annie.ca", 99 | "address": { 100 | "street": "Skiles Walks", 101 | "suite": "Suite 351", 102 | "city": "Roscoeview", 103 | "zipcode": "33263", 104 | "geo": { 105 | "lat": "-31.8129", 106 | "lng": "62.5342" 107 | } 108 | }, 109 | "phone": "(254)954-1289", 110 | "website": "demarco.info", 111 | "company": { 112 | "name": "Keebler LLC", 113 | "catchPhrase": "User-centric fault-tolerant solution", 114 | "bs": "revolutionize end-to-end systems" 115 | } 116 | }, 117 | { 118 | "id": 6, 119 | "name": "Mrs. Dennis Schulist", 120 | "username": "Leopoldo_Corkery", 121 | "email": "Karley_Dach@jasper.info", 122 | "address": { 123 | "street": "Norberto Crossing", 124 | "suite": "Apt. 950", 125 | "city": "South Christy", 126 | "zipcode": "23505-1337", 127 | "geo": { 128 | "lat": "-71.4197", 129 | "lng": "71.7478" 130 | } 131 | }, 132 | "phone": "1-477-935-8478 x6430", 133 | "website": "ola.org", 134 | "company": { 135 | "name": "Considine-Lockman", 136 | "catchPhrase": "Synchronised bottom-line interface", 137 | "bs": "e-enable innovative applications" 138 | } 139 | }, 140 | { 141 | "id": 7, 142 | "name": "Kurtis Weissnat", 143 | "username": "Elwyn.Skiles", 144 | "email": "Telly.Hoeger@billy.biz", 145 | "address": { 146 | "street": "Rex Trail", 147 | "suite": "Suite 280", 148 | "city": "Howemouth", 149 | "zipcode": "58804-1099", 150 | "geo": { 151 | "lat": "24.8918", 152 | "lng": "21.8984" 153 | } 154 | }, 155 | "phone": "210.067.6132", 156 | "website": "elvis.io", 157 | "company": { 158 | "name": "Johns Group", 159 | "catchPhrase": "Configurable multimedia task-force", 160 | "bs": "generate enterprise e-tailers" 161 | } 162 | }, 163 | { 164 | "id": 8, 165 | "name": "Nicholas Runolfsdottir V", 166 | "username": "Maxime_Nienow", 167 | "email": "Sherwood@rosamond.me", 168 | "address": { 169 | "street": "Ellsworth Summit", 170 | "suite": "Suite 729", 171 | "city": "Aliyaview", 172 | "zipcode": "45169", 173 | "geo": { 174 | "lat": "-14.3990", 175 | "lng": "-120.7677" 176 | } 177 | }, 178 | "phone": "586.493.6943 x140", 179 | "website": "jacynthe.com", 180 | "company": { 181 | "name": "Abernathy Group", 182 | "catchPhrase": "Implemented secondary concept", 183 | "bs": "e-enable extensible e-tailers" 184 | } 185 | }, 186 | { 187 | "id": 9, 188 | "name": "Glenna Reichert", 189 | "username": "Delphine", 190 | "email": "Chaim_McDermott@dana.io", 191 | "address": { 192 | "street": "Dayna Park", 193 | "suite": "Suite 449", 194 | "city": "Bartholomebury", 195 | "zipcode": "76495-3109", 196 | "geo": { 197 | "lat": "24.6463", 198 | "lng": "-168.8889" 199 | } 200 | }, 201 | "phone": "(775)976-6794 x41206", 202 | "website": "conrad.com", 203 | "company": { 204 | "name": "Yost and Sons", 205 | "catchPhrase": "Switchable contextually-based project", 206 | "bs": "aggregate real-time technologies" 207 | } 208 | }, 209 | { 210 | "id": 10, 211 | "name": "Clementina DuBuque", 212 | "username": "Moriah.Stanton", 213 | "email": "Rey.Padberg@karina.biz", 214 | "address": { 215 | "street": "Kattie Turnpike", 216 | "suite": "Suite 198", 217 | "city": "Lebsackbury", 218 | "zipcode": "31428-2261", 219 | "geo": { 220 | "lat": "-38.2386", 221 | "lng": "57.2232" 222 | } 223 | }, 224 | "phone": "024-648-3804", 225 | "website": "ambrose.net", 226 | "company": { 227 | "name": "Hoeger LLC", 228 | "catchPhrase": "Centralized empowering task-force", 229 | "bs": "target end-to-end models" 230 | } 231 | } 232 | ] -------------------------------------------------------------------------------- /77. Solution 2 - Retrieving a few users from server/jsplaceholder.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | response = requests.get("https://jsonplaceholder.typicode.com/todos") 5 | 6 | def count_completed_task_frequency(tasks): 7 | completedTasksFrequencyByUser = dict() 8 | for entry in tasks: 9 | if (entry["completed"] == True): 10 | try: 11 | completedTasksFrequencyByUser[entry["userId"]] += 1 12 | except KeyError: 13 | completedTasksFrequencyByUser[entry["userId"]] = 1 14 | return completedTasksFrequencyByUser 15 | 16 | def get_users_with_top_completed_tasks(completedTasksFrequencyByUser): 17 | usersIdWithMaxCompletedAmountOfTasks = [] 18 | maxAmountOfCompletedTasks = max(completedTasksFrequencyByUser.values()) 19 | for userId, numberOfCompletedTasks in completedTasksFrequencyByUser.items(): 20 | if (numberOfCompletedTasks == maxAmountOfCompletedTasks): 21 | usersIdWithMaxCompletedAmountOfTasks.append(userId) 22 | 23 | return usersIdWithMaxCompletedAmountOfTasks 24 | 25 | try: 26 | tasks = response.json() 27 | except json.decoder.JSONDecodeError: 28 | print("The content is not JSON") 29 | else: 30 | completedTasksFrequencyByUser = count_completed_task_frequency(tasks) 31 | usersIdWithMaxCompletedAmountOfTasks = get_users_with_top_completed_tasks(completedTasksFrequencyByUser) 32 | 33 | 34 | 35 | 36 | #solution 1 37 | """ 38 | r = requests.get("https://jsonplaceholder.typicode.com/users") 39 | users = r.json() 40 | 41 | for user in users: 42 | if (user["id"] in usersIdWithMaxCompletedAmountOfTasks): 43 | print("Cookie for:", user["name"]) 44 | usersIdWithMaxCompletedAmountOfTasks.remove(user["id"]) 45 | """ 46 | #solution 2 47 | """ 48 | for userId in usersIdWithMaxCompletedAmountOfTasks: 49 | r = requests.get("https://jsonplaceholder.typicode.com/users/"+str(userId)) 50 | user = r.json() 51 | print(user["name"]) 52 | """ 53 | -------------------------------------------------------------------------------- /77. Solution 2 - Retrieving a few users from server/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "name": "Leanne Graham", 5 | "username": "Bret", 6 | "email": "Sincere@april.biz", 7 | "address": { 8 | "street": "Kulas Light", 9 | "suite": "Apt. 556", 10 | "city": "Gwenborough", 11 | "zipcode": "92998-3874", 12 | "geo": { 13 | "lat": "-37.3159", 14 | "lng": "81.1496" 15 | } 16 | }, 17 | "phone": "1-770-736-8031 x56442", 18 | "website": "hildegard.org", 19 | "company": { 20 | "name": "Romaguera-Crona", 21 | "catchPhrase": "Multi-layered client-server neural-net", 22 | "bs": "harness real-time e-markets" 23 | } 24 | }, 25 | { 26 | "id": 2, 27 | "name": "Ervin Howell", 28 | "username": "Antonette", 29 | "email": "Shanna@melissa.tv", 30 | "address": { 31 | "street": "Victor Plains", 32 | "suite": "Suite 879", 33 | "city": "Wisokyburgh", 34 | "zipcode": "90566-7771", 35 | "geo": { 36 | "lat": "-43.9509", 37 | "lng": "-34.4618" 38 | } 39 | }, 40 | "phone": "010-692-6593 x09125", 41 | "website": "anastasia.net", 42 | "company": { 43 | "name": "Deckow-Crist", 44 | "catchPhrase": "Proactive didactic contingency", 45 | "bs": "synergize scalable supply-chains" 46 | } 47 | }, 48 | { 49 | "id": 3, 50 | "name": "Clementine Bauch", 51 | "username": "Samantha", 52 | "email": "Nathan@yesenia.net", 53 | "address": { 54 | "street": "Douglas Extension", 55 | "suite": "Suite 847", 56 | "city": "McKenziehaven", 57 | "zipcode": "59590-4157", 58 | "geo": { 59 | "lat": "-68.6102", 60 | "lng": "-47.0653" 61 | } 62 | }, 63 | "phone": "1-463-123-4447", 64 | "website": "ramiro.info", 65 | "company": { 66 | "name": "Romaguera-Jacobson", 67 | "catchPhrase": "Face to face bifurcated interface", 68 | "bs": "e-enable strategic applications" 69 | } 70 | }, 71 | { 72 | "id": 4, 73 | "name": "Patricia Lebsack", 74 | "username": "Karianne", 75 | "email": "Julianne.OConner@kory.org", 76 | "address": { 77 | "street": "Hoeger Mall", 78 | "suite": "Apt. 692", 79 | "city": "South Elvis", 80 | "zipcode": "53919-4257", 81 | "geo": { 82 | "lat": "29.4572", 83 | "lng": "-164.2990" 84 | } 85 | }, 86 | "phone": "493-170-9623 x156", 87 | "website": "kale.biz", 88 | "company": { 89 | "name": "Robel-Corkery", 90 | "catchPhrase": "Multi-tiered zero tolerance productivity", 91 | "bs": "transition cutting-edge web services" 92 | } 93 | }, 94 | { 95 | "id": 5, 96 | "name": "Chelsey Dietrich", 97 | "username": "Kamren", 98 | "email": "Lucio_Hettinger@annie.ca", 99 | "address": { 100 | "street": "Skiles Walks", 101 | "suite": "Suite 351", 102 | "city": "Roscoeview", 103 | "zipcode": "33263", 104 | "geo": { 105 | "lat": "-31.8129", 106 | "lng": "62.5342" 107 | } 108 | }, 109 | "phone": "(254)954-1289", 110 | "website": "demarco.info", 111 | "company": { 112 | "name": "Keebler LLC", 113 | "catchPhrase": "User-centric fault-tolerant solution", 114 | "bs": "revolutionize end-to-end systems" 115 | } 116 | }, 117 | { 118 | "id": 6, 119 | "name": "Mrs. Dennis Schulist", 120 | "username": "Leopoldo_Corkery", 121 | "email": "Karley_Dach@jasper.info", 122 | "address": { 123 | "street": "Norberto Crossing", 124 | "suite": "Apt. 950", 125 | "city": "South Christy", 126 | "zipcode": "23505-1337", 127 | "geo": { 128 | "lat": "-71.4197", 129 | "lng": "71.7478" 130 | } 131 | }, 132 | "phone": "1-477-935-8478 x6430", 133 | "website": "ola.org", 134 | "company": { 135 | "name": "Considine-Lockman", 136 | "catchPhrase": "Synchronised bottom-line interface", 137 | "bs": "e-enable innovative applications" 138 | } 139 | }, 140 | { 141 | "id": 7, 142 | "name": "Kurtis Weissnat", 143 | "username": "Elwyn.Skiles", 144 | "email": "Telly.Hoeger@billy.biz", 145 | "address": { 146 | "street": "Rex Trail", 147 | "suite": "Suite 280", 148 | "city": "Howemouth", 149 | "zipcode": "58804-1099", 150 | "geo": { 151 | "lat": "24.8918", 152 | "lng": "21.8984" 153 | } 154 | }, 155 | "phone": "210.067.6132", 156 | "website": "elvis.io", 157 | "company": { 158 | "name": "Johns Group", 159 | "catchPhrase": "Configurable multimedia task-force", 160 | "bs": "generate enterprise e-tailers" 161 | } 162 | }, 163 | { 164 | "id": 8, 165 | "name": "Nicholas Runolfsdottir V", 166 | "username": "Maxime_Nienow", 167 | "email": "Sherwood@rosamond.me", 168 | "address": { 169 | "street": "Ellsworth Summit", 170 | "suite": "Suite 729", 171 | "city": "Aliyaview", 172 | "zipcode": "45169", 173 | "geo": { 174 | "lat": "-14.3990", 175 | "lng": "-120.7677" 176 | } 177 | }, 178 | "phone": "586.493.6943 x140", 179 | "website": "jacynthe.com", 180 | "company": { 181 | "name": "Abernathy Group", 182 | "catchPhrase": "Implemented secondary concept", 183 | "bs": "e-enable extensible e-tailers" 184 | } 185 | }, 186 | { 187 | "id": 9, 188 | "name": "Glenna Reichert", 189 | "username": "Delphine", 190 | "email": "Chaim_McDermott@dana.io", 191 | "address": { 192 | "street": "Dayna Park", 193 | "suite": "Suite 449", 194 | "city": "Bartholomebury", 195 | "zipcode": "76495-3109", 196 | "geo": { 197 | "lat": "24.6463", 198 | "lng": "-168.8889" 199 | } 200 | }, 201 | "phone": "(775)976-6794 x41206", 202 | "website": "conrad.com", 203 | "company": { 204 | "name": "Yost and Sons", 205 | "catchPhrase": "Switchable contextually-based project", 206 | "bs": "aggregate real-time technologies" 207 | } 208 | }, 209 | { 210 | "id": 10, 211 | "name": "Clementina DuBuque", 212 | "username": "Moriah.Stanton", 213 | "email": "Rey.Padberg@karina.biz", 214 | "address": { 215 | "street": "Kattie Turnpike", 216 | "suite": "Suite 198", 217 | "city": "Lebsackbury", 218 | "zipcode": "31428-2261", 219 | "geo": { 220 | "lat": "-38.2386", 221 | "lng": "57.2232" 222 | } 223 | }, 224 | "phone": "024-648-3804", 225 | "website": "ambrose.net", 226 | "company": { 227 | "name": "Hoeger LLC", 228 | "catchPhrase": "Centralized empowering task-force", 229 | "bs": "target end-to-end models" 230 | } 231 | } 232 | ] -------------------------------------------------------------------------------- /78. Solution 3 - Retrieving a few users from server/jsplaceholder.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | response = requests.get("https://jsonplaceholder.typicode.com/todos") 5 | 6 | def count_completed_task_frequency(tasks): 7 | completedTasksFrequencyByUser = dict() 8 | for entry in tasks: 9 | if (entry["completed"] == True): 10 | try: 11 | completedTasksFrequencyByUser[entry["userId"]] += 1 12 | except KeyError: 13 | completedTasksFrequencyByUser[entry["userId"]] = 1 14 | return completedTasksFrequencyByUser 15 | 16 | def get_users_with_top_completed_tasks(completedTasksFrequencyByUser): 17 | usersIdWithMaxCompletedAmountOfTasks = [] 18 | maxAmountOfCompletedTasks = max(completedTasksFrequencyByUser.values()) 19 | for userId, numberOfCompletedTasks in completedTasksFrequencyByUser.items(): 20 | if (numberOfCompletedTasks == maxAmountOfCompletedTasks): 21 | usersIdWithMaxCompletedAmountOfTasks.append(userId) 22 | 23 | return usersIdWithMaxCompletedAmountOfTasks 24 | 25 | try: 26 | tasks = response.json() 27 | except json.decoder.JSONDecodeError: 28 | print("The content is not JSON") 29 | else: 30 | completedTasksFrequencyByUser = count_completed_task_frequency(tasks) 31 | usersIdWithMaxCompletedAmountOfTasks = get_users_with_top_completed_tasks(completedTasksFrequencyByUser) 32 | 33 | 34 | 35 | 36 | #solution 1 37 | """ 38 | r = requests.get("https://jsonplaceholder.typicode.com/users") 39 | users = r.json() 40 | 41 | for user in users: 42 | if (user["id"] in usersIdWithMaxCompletedAmountOfTasks): 43 | print("Cookie for:", user["name"]) 44 | usersIdWithMaxCompletedAmountOfTasks.remove(user["id"]) 45 | """ 46 | #solution 2 47 | """ 48 | for userId in usersIdWithMaxCompletedAmountOfTasks: 49 | r = requests.get("https://jsonplaceholder.typicode.com/users/"+str(userId)) 50 | user = r.json() 51 | print(user["name"]) 52 | """ 53 | #solution 3 54 | def change_list_into_conj_of_params(my_list, key="id"): 55 | conjuction_params_string = key + "=" 56 | 57 | lastIteration = len(my_list) 58 | i = 0 59 | for item in my_list: 60 | i += 1 61 | if (i == lastIteration): 62 | conjuction_params_string += str(item) 63 | else: 64 | conjuction_params_string += str(item) + "&" + key + "=" 65 | 66 | return conjuction_params_string 67 | 68 | conj_params = change_list_into_conj_of_params(usersIdWithMaxCompletedAmountOfTasks) 69 | 70 | r = requests.get("https://jsonplaceholder.typicode.com/users/", params=conj_params) 71 | users = r.json() 72 | 73 | for user in users: 74 | print("HEY COOKIE FOR YOU: " + user["name"]) 75 | 76 | 77 | -------------------------------------------------------------------------------- /78. Solution 3 - Retrieving a few users from server/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "name": "Leanne Graham", 5 | "username": "Bret", 6 | "email": "Sincere@april.biz", 7 | "address": { 8 | "street": "Kulas Light", 9 | "suite": "Apt. 556", 10 | "city": "Gwenborough", 11 | "zipcode": "92998-3874", 12 | "geo": { 13 | "lat": "-37.3159", 14 | "lng": "81.1496" 15 | } 16 | }, 17 | "phone": "1-770-736-8031 x56442", 18 | "website": "hildegard.org", 19 | "company": { 20 | "name": "Romaguera-Crona", 21 | "catchPhrase": "Multi-layered client-server neural-net", 22 | "bs": "harness real-time e-markets" 23 | } 24 | }, 25 | { 26 | "id": 2, 27 | "name": "Ervin Howell", 28 | "username": "Antonette", 29 | "email": "Shanna@melissa.tv", 30 | "address": { 31 | "street": "Victor Plains", 32 | "suite": "Suite 879", 33 | "city": "Wisokyburgh", 34 | "zipcode": "90566-7771", 35 | "geo": { 36 | "lat": "-43.9509", 37 | "lng": "-34.4618" 38 | } 39 | }, 40 | "phone": "010-692-6593 x09125", 41 | "website": "anastasia.net", 42 | "company": { 43 | "name": "Deckow-Crist", 44 | "catchPhrase": "Proactive didactic contingency", 45 | "bs": "synergize scalable supply-chains" 46 | } 47 | }, 48 | { 49 | "id": 3, 50 | "name": "Clementine Bauch", 51 | "username": "Samantha", 52 | "email": "Nathan@yesenia.net", 53 | "address": { 54 | "street": "Douglas Extension", 55 | "suite": "Suite 847", 56 | "city": "McKenziehaven", 57 | "zipcode": "59590-4157", 58 | "geo": { 59 | "lat": "-68.6102", 60 | "lng": "-47.0653" 61 | } 62 | }, 63 | "phone": "1-463-123-4447", 64 | "website": "ramiro.info", 65 | "company": { 66 | "name": "Romaguera-Jacobson", 67 | "catchPhrase": "Face to face bifurcated interface", 68 | "bs": "e-enable strategic applications" 69 | } 70 | }, 71 | { 72 | "id": 4, 73 | "name": "Patricia Lebsack", 74 | "username": "Karianne", 75 | "email": "Julianne.OConner@kory.org", 76 | "address": { 77 | "street": "Hoeger Mall", 78 | "suite": "Apt. 692", 79 | "city": "South Elvis", 80 | "zipcode": "53919-4257", 81 | "geo": { 82 | "lat": "29.4572", 83 | "lng": "-164.2990" 84 | } 85 | }, 86 | "phone": "493-170-9623 x156", 87 | "website": "kale.biz", 88 | "company": { 89 | "name": "Robel-Corkery", 90 | "catchPhrase": "Multi-tiered zero tolerance productivity", 91 | "bs": "transition cutting-edge web services" 92 | } 93 | }, 94 | { 95 | "id": 5, 96 | "name": "Chelsey Dietrich", 97 | "username": "Kamren", 98 | "email": "Lucio_Hettinger@annie.ca", 99 | "address": { 100 | "street": "Skiles Walks", 101 | "suite": "Suite 351", 102 | "city": "Roscoeview", 103 | "zipcode": "33263", 104 | "geo": { 105 | "lat": "-31.8129", 106 | "lng": "62.5342" 107 | } 108 | }, 109 | "phone": "(254)954-1289", 110 | "website": "demarco.info", 111 | "company": { 112 | "name": "Keebler LLC", 113 | "catchPhrase": "User-centric fault-tolerant solution", 114 | "bs": "revolutionize end-to-end systems" 115 | } 116 | }, 117 | { 118 | "id": 6, 119 | "name": "Mrs. Dennis Schulist", 120 | "username": "Leopoldo_Corkery", 121 | "email": "Karley_Dach@jasper.info", 122 | "address": { 123 | "street": "Norberto Crossing", 124 | "suite": "Apt. 950", 125 | "city": "South Christy", 126 | "zipcode": "23505-1337", 127 | "geo": { 128 | "lat": "-71.4197", 129 | "lng": "71.7478" 130 | } 131 | }, 132 | "phone": "1-477-935-8478 x6430", 133 | "website": "ola.org", 134 | "company": { 135 | "name": "Considine-Lockman", 136 | "catchPhrase": "Synchronised bottom-line interface", 137 | "bs": "e-enable innovative applications" 138 | } 139 | }, 140 | { 141 | "id": 7, 142 | "name": "Kurtis Weissnat", 143 | "username": "Elwyn.Skiles", 144 | "email": "Telly.Hoeger@billy.biz", 145 | "address": { 146 | "street": "Rex Trail", 147 | "suite": "Suite 280", 148 | "city": "Howemouth", 149 | "zipcode": "58804-1099", 150 | "geo": { 151 | "lat": "24.8918", 152 | "lng": "21.8984" 153 | } 154 | }, 155 | "phone": "210.067.6132", 156 | "website": "elvis.io", 157 | "company": { 158 | "name": "Johns Group", 159 | "catchPhrase": "Configurable multimedia task-force", 160 | "bs": "generate enterprise e-tailers" 161 | } 162 | }, 163 | { 164 | "id": 8, 165 | "name": "Nicholas Runolfsdottir V", 166 | "username": "Maxime_Nienow", 167 | "email": "Sherwood@rosamond.me", 168 | "address": { 169 | "street": "Ellsworth Summit", 170 | "suite": "Suite 729", 171 | "city": "Aliyaview", 172 | "zipcode": "45169", 173 | "geo": { 174 | "lat": "-14.3990", 175 | "lng": "-120.7677" 176 | } 177 | }, 178 | "phone": "586.493.6943 x140", 179 | "website": "jacynthe.com", 180 | "company": { 181 | "name": "Abernathy Group", 182 | "catchPhrase": "Implemented secondary concept", 183 | "bs": "e-enable extensible e-tailers" 184 | } 185 | }, 186 | { 187 | "id": 9, 188 | "name": "Glenna Reichert", 189 | "username": "Delphine", 190 | "email": "Chaim_McDermott@dana.io", 191 | "address": { 192 | "street": "Dayna Park", 193 | "suite": "Suite 449", 194 | "city": "Bartholomebury", 195 | "zipcode": "76495-3109", 196 | "geo": { 197 | "lat": "24.6463", 198 | "lng": "-168.8889" 199 | } 200 | }, 201 | "phone": "(775)976-6794 x41206", 202 | "website": "conrad.com", 203 | "company": { 204 | "name": "Yost and Sons", 205 | "catchPhrase": "Switchable contextually-based project", 206 | "bs": "aggregate real-time technologies" 207 | } 208 | }, 209 | { 210 | "id": 10, 211 | "name": "Clementina DuBuque", 212 | "username": "Moriah.Stanton", 213 | "email": "Rey.Padberg@karina.biz", 214 | "address": { 215 | "street": "Kattie Turnpike", 216 | "suite": "Suite 198", 217 | "city": "Lebsackbury", 218 | "zipcode": "31428-2261", 219 | "geo": { 220 | "lat": "-38.2386", 221 | "lng": "57.2232" 222 | } 223 | }, 224 | "phone": "024-648-3804", 225 | "website": "ambrose.net", 226 | "company": { 227 | "name": "Hoeger LLC", 228 | "catchPhrase": "Centralized empowering task-force", 229 | "bs": "target end-to-end models" 230 | } 231 | } 232 | ] -------------------------------------------------------------------------------- /79. defaultdict/collection_defaultdict.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | from collections import defaultdict 4 | 5 | response = requests.get("https://jsonplaceholder.typicode.com/todos") 6 | 7 | 8 | def count_completed_task_frequency(tasks): 9 | completedTasksFrequencyByUser = defaultdict(int) 10 | for entry in tasks: 11 | if (entry["completed"] == True): 12 | completedTasksFrequencyByUser[entry["userId"]] += 1 13 | 14 | return completedTasksFrequencyByUser 15 | 16 | def get_users_with_top_completed_tasks(completedTasksFrequencyByUser): 17 | usersIdWithMaxCompletedAmountOfTasks = [] 18 | maxAmountOfCompletedTasks = max(completedTasksFrequencyByUser.values()) 19 | for userId, numberOfCompletedTasks in completedTasksFrequencyByUser.items(): 20 | if (numberOfCompletedTasks == maxAmountOfCompletedTasks): 21 | usersIdWithMaxCompletedAmountOfTasks.append(userId) 22 | 23 | return usersIdWithMaxCompletedAmountOfTasks 24 | 25 | try: 26 | tasks = response.json() 27 | except json.decoder.JSONDecodeError: 28 | print("The content is not JSON") 29 | else: 30 | completedTasksFrequencyByUser = count_completed_task_frequency(tasks) 31 | usersIdWithMaxCompletedAmountOfTasks = get_users_with_top_completed_tasks(completedTasksFrequencyByUser) 32 | 33 | 34 | 35 | 36 | #solution 1 37 | """ 38 | r = requests.get("https://jsonplaceholder.typicode.com/users") 39 | users = r.json() 40 | 41 | for user in users: 42 | if (user["id"] in usersIdWithMaxCompletedAmountOfTasks): 43 | print("Cookie for:", user["name"]) 44 | usersIdWithMaxCompletedAmountOfTasks.remove(user["id"]) 45 | """ 46 | #solution 2 47 | """ 48 | for userId in usersIdWithMaxCompletedAmountOfTasks: 49 | r = requests.get("https://jsonplaceholder.typicode.com/users/"+str(userId)) 50 | user = r.json() 51 | print(user["name"]) 52 | """ 53 | #solution 3 54 | def change_list_into_conj_of_params(my_list, key="id"): 55 | conjuction_params_string = key + "=" 56 | 57 | lastIteration = len(my_list) 58 | i = 0 59 | for item in my_list: 60 | i += 1 61 | if (i == lastIteration): 62 | conjuction_params_string += str(item) 63 | else: 64 | conjuction_params_string += str(item) + "&" + key + "=" 65 | 66 | return conjuction_params_string 67 | 68 | conj_params = change_list_into_conj_of_params(usersIdWithMaxCompletedAmountOfTasks) 69 | 70 | r = requests.get("https://jsonplaceholder.typicode.com/users/", params=conj_params) 71 | users = r.json() 72 | 73 | for user in users: 74 | print("HEY COOKIE FOR YOU: " + user["name"]) 75 | 76 | -------------------------------------------------------------------------------- /80. What is public API/public_api.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | """ 4 | 5 | API - Application Programming Interface 6 | 7 | inter - between 8 | 9 | ATM - cash machine 10 | 11 | """ 12 | 13 | 14 | response = requests.get("https://api.stackexchange.com/2.2/answers?order=desc&sort=activity&site=stackoverflow") 15 | 16 | try: 17 | answers = response.json() 18 | except json.decoder.JSONDecodeError: 19 | print("The content is not JSON") 20 | else: 21 | print(answers) 22 | 23 | 24 | -------------------------------------------------------------------------------- /81. Getting specific JSON from stackoverflow/specific_json.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import pprint 4 | import webbrowser 5 | 6 | """ 7 | 8 | API - Application Programming Interface 9 | 10 | Questions should follow below rules: 11 | 1) minimum 15 points (score) 12 | 2) sorted in descending order 13 | 3) from last week 14 | 4) from the Python category 15 | 16 | """ 17 | params = { 18 | "site": "stackoverflow", 19 | "sort": "votes", 20 | "min" : 15, 21 | "order" : "desc", 22 | "fromdate" : "2019-08-03", 23 | "tagged": "python" 24 | 25 | 26 | } 27 | 28 | response = requests.get("https://api.stackexchange.com/2.2/questions", params) 29 | 30 | try: 31 | questions = response.json() 32 | except json.decoder.JSONDecodeError: 33 | print("The content is not JSON") 34 | else: 35 | for question in questions["items"]: 36 | webbrowser.open_new_tab(question["link"]) 37 | 38 | 39 | -------------------------------------------------------------------------------- /82. Processing JSON from stack/processing_json.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import pprint 4 | 5 | """ 6 | 7 | API - Application Programming Interface 8 | 9 | Questions should follow below rules: 10 | 1) minimum 15 points (score) 11 | 2) sorted in descending order 12 | 3) from last week 13 | 4) from the Python category 14 | 15 | """ 16 | params = { 17 | "site": "stackoverflow", 18 | "sort": "votes", 19 | "min" : 15, 20 | "order" : "desc", 21 | "fromdate" : "2019-08-03", 22 | "tagged": "python" 23 | 24 | 25 | } 26 | 27 | response = requests.get("https://api.stackexchange.com/2.2/questions", params) 28 | 29 | try: 30 | questions = response.json() 31 | except json.decoder.JSONDecodeError: 32 | print("The content is not JSON") 33 | else: 34 | pprint.pprint(questions) 35 | 36 | 37 | -------------------------------------------------------------------------------- /83. datetime - getting records from exactly last week/gettingrecordlastweek.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import webbrowser 4 | from datetime import datetime, timedelta 5 | 6 | 7 | """ 8 | time stamp 9 | 10 | 1st 1970 - stamp time 11 | 12 | """ 13 | timeBefore = timedelta(days = 7) 14 | 15 | searchDate = datetime.today() - timeBefore 16 | 17 | 18 | params = { 19 | "site": "stackoverflow", 20 | "sort": "votes", 21 | "min" : 15, 22 | "order" : "desc", 23 | "fromdate" : int(searchDate.timestamp()), 24 | "tagged": "python" 25 | 26 | 27 | } 28 | 29 | response = requests.get("https://api.stackexchange.com/2.2/questions", params) 30 | 31 | try: 32 | questions = response.json() 33 | except json.decoder.JSONDecodeError: 34 | print("The content is not JSON") 35 | else: 36 | for question in questions["items"]: 37 | webbrowser.open_new_tab(question["link"]) 38 | 39 | 40 | -------------------------------------------------------------------------------- /84. cat facts/catfacts.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import webbrowser 4 | from pprint import pprint 5 | 6 | params = { 7 | "amount": 5 8 | 9 | } 10 | 11 | response = requests.get("https://cat-fact.herokuapp.com/facts/random/", 12 | params) 13 | 14 | try: 15 | content = response.json() 16 | except json.decoder.JSONDecodeError: 17 | print("The content is not JSON") 18 | else: 19 | for cat in content: 20 | print(cat["text"]) 21 | 22 | 23 | -------------------------------------------------------------------------------- /85. apikey - authorization/apikeyauth.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import webbrowser 4 | from pprint import pprint 5 | """ 6 | authorization 7 | """ 8 | params = { 9 | "api_key" : "yourkeygoeshere", 10 | "year" : 2019, 11 | "country" : "gb", 12 | "month" : 12, 13 | "type" : "national" 14 | } 15 | 16 | response = requests.get("https://calendarific.com/api/v2/holidays/", 17 | params) 18 | 19 | try: 20 | content = response.json() 21 | except json.decoder.JSONDecodeError: 22 | print("The content is not JSON") 23 | else: 24 | pprint(content) 25 | 26 | 27 | -------------------------------------------------------------------------------- /86. sending custom header with apikey/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/86. sending custom header with apikey/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /86. sending custom header with apikey/apikeyauth.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import webbrowser 4 | import settings 5 | 6 | from pprint import pprint 7 | 8 | headers = { 9 | "x-api-key" : settings.apiKey 10 | } 11 | 12 | 13 | r = requests.get('https://api.thecatapi.com/v1/favourites/', 14 | headers=headers) 15 | 16 | 17 | try: 18 | content = r.json() 19 | except json.decoder.JSONDecodeError: 20 | print("Niepoprawny format", r.text) 21 | else: 22 | print(content) 23 | 24 | -------------------------------------------------------------------------------- /86. sending custom header with apikey/settings.py: -------------------------------------------------------------------------------- 1 | apiKey = "17ed588f-ec8a-46bb-bcf9-58810bc285ef" 2 | 3 | -------------------------------------------------------------------------------- /87. EXERCISE Cat system - introduction/catsystem.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import webbrowser 4 | import settings 5 | 6 | from pprint import pprint 7 | 8 | headers = { 9 | "x-api-key" : settings.apiKey 10 | } 11 | 12 | 13 | def get_json_content_from_response(response): 14 | try: 15 | content = response.json() 16 | except json.decoder.JSONDecodeError: 17 | print("Improper format", response.text) 18 | else: 19 | return content 20 | 21 | def get_favorite_cats(userId): 22 | params = { 23 | "sub_id" : userId 24 | } 25 | r = requests.get('https://api.thecatapi.com/v1/favourites/', params, 26 | headers=headers) 27 | 28 | return get_json_content_from_response(r) 29 | 30 | 31 | def get_random_cat(): 32 | 33 | r = requests.get('https://api.thecatapi.com/v1/images/search', 34 | headers=headers) 35 | 36 | return get_json_content_from_response(r)[0] 37 | 38 | 39 | print("Hi, provide login and pw: ") 40 | #checking whether the login and pw are correct 41 | #assuming: loggin completed correctly 42 | #we retrieve from database: userId and username for further reference 43 | 44 | userId = "agh2m" 45 | userName = "Arkadiusz" 46 | 47 | print("Hi, " + userName) 48 | 49 | favouriteCats = get_favorite_cats(userId) 50 | 51 | print("Your favourite cats are: ", favouriteCats) 52 | 53 | randomCat = get_random_cat() 54 | 55 | print("Drawn kitten: ", randomCat["url"]) 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /88. POST - adding favourite cat/catsystem.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import webbrowser 4 | import settings 5 | 6 | from pprint import pprint 7 | 8 | headers = { 9 | "x-api-key" : settings.apiKey 10 | } 11 | 12 | 13 | def get_json_content_from_response(response): 14 | try: 15 | content = response.json() 16 | except json.decoder.JSONDecodeError: 17 | print("Improper format", response.text) 18 | else: 19 | return content 20 | 21 | def get_favorite_cats(userId): 22 | params = { 23 | "sub_id" : userId 24 | } 25 | r = requests.get('https://api.thecatapi.com/v1/favourites/', params, 26 | headers=headers) 27 | 28 | return get_json_content_from_response(r) 29 | 30 | 31 | def get_random_cat(): 32 | 33 | r = requests.get('https://api.thecatapi.com/v1/images/search', 34 | headers=headers) 35 | 36 | return get_json_content_from_response(r)[0] 37 | 38 | def add_favourite_cat(userId, catId): 39 | catData = { 40 | "image_id" : catId, 41 | "sub_id" : userId 42 | } 43 | r = requests.post('https://api.thecatapi.com/v1/favourites/', json = catData, 44 | headers=headers) 45 | 46 | return get_json_content_from_response(r) 47 | 48 | print("Hi, provide login and pw: ") 49 | #checking whether the login and pw are correct 50 | #assuming: loggin completed correctly 51 | #we retrieve from database: userId and username for further reference 52 | 53 | userId = "agh2m" 54 | userName = "Arkadiusz" 55 | 56 | print("Hi, " + userName) 57 | 58 | favouriteCats = get_favorite_cats(userId) 59 | 60 | print("Your favourite cats are: ", favouriteCats) 61 | 62 | randomCat = get_random_cat() 63 | 64 | print("Drawn kitten: ", randomCat["url"]) 65 | 66 | addToFavouriteResponse = input("Do you want to add it to your favourite list? Y/N") 67 | 68 | 69 | if (addToFavouriteResponse.upper() == "Y"): 70 | print(add_favourite_cat(userId, randomCat["id"])) 71 | else: 72 | print("Why, you brutal being, the cat will be sad") 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /89. DELETE - removing favourite cat/catsystem.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import webbrowser 4 | import settings 5 | 6 | from pprint import pprint 7 | 8 | headers = { 9 | "x-api-key" : settings.apiKey 10 | } 11 | 12 | 13 | def get_json_content_from_response(response): 14 | try: 15 | content = response.json() 16 | except json.decoder.JSONDecodeError: 17 | print("Improper format", response.text) 18 | else: 19 | return content 20 | 21 | def get_favorite_cats(userId): 22 | params = { 23 | "sub_id" : userId 24 | } 25 | r = requests.get('https://api.thecatapi.com/v1/favourites/', params, 26 | headers=headers) 27 | 28 | return get_json_content_from_response(r) 29 | 30 | 31 | def get_random_cat(): 32 | 33 | r = requests.get('https://api.thecatapi.com/v1/images/search', 34 | headers=headers) 35 | 36 | return get_json_content_from_response(r)[0] 37 | 38 | def add_favourite_cat(userId, catId): 39 | catData = { 40 | "image_id" : catId, 41 | "sub_id" : userId 42 | } 43 | r = requests.post('https://api.thecatapi.com/v1/favourites/', json = catData, 44 | headers=headers) 45 | 46 | return get_json_content_from_response(r) 47 | 48 | 49 | def remove_favourite_cat(favouriteCatId): 50 | r = requests.delete('https://api.thecatapi.com/v1/favourites/'+favouriteCatId, 51 | headers=headers) 52 | 53 | return get_json_content_from_response(r) 54 | 55 | print("Hi, provide login and pw: ") 56 | #checking whether the login and pw are correct 57 | #assuming: loggin completed correctly 58 | #we retrieve from database: userId and username for further reference 59 | 60 | userId = "agh2m" 61 | userName = "Arkadiusz" 62 | 63 | print("Hi, " + userName) 64 | 65 | favouriteCats = get_favorite_cats(userId) 66 | 67 | print("Your favourite cats are: ", favouriteCats) 68 | 69 | randomCat = get_random_cat() 70 | 71 | print("Drawn kitten: ", randomCat["url"]) 72 | 73 | addToFavouriteResponse = input("Do you want to add it to your favourite list? Y/N") 74 | 75 | 76 | if (addToFavouriteResponse.upper() == "Y"): 77 | resultFromAddingFavouriteCat = add_favourite_cat(userId, randomCat["id"]) 78 | newlyAddedCatDict = {resultFromAddingFavouriteCat["id"] : randomCat["url"] } 79 | else: 80 | print("Why, you brutal being, the cat will be sad") 81 | 82 | 83 | favouriteCatsById = { 84 | cat["id"] : cat["image"]["url"] 85 | for cat in favouriteCats 86 | } 87 | 88 | favouriteCatsById.update(newlyAddedCatDict) 89 | 90 | print(favouriteCatsById) 91 | 92 | idCatToRemove = input("So... you don't have a heart, provide id of cat to delete: ") 93 | 94 | 95 | 96 | print(remove_favourite_cat(idCatToRemove)) 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /90. Setting workspace in VSC/python english files.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/90. Setting workspace in VSC/python english files.zip -------------------------------------------------------------------------------- /90. Setting workspace in VSC/python english files/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Current File", 9 | "type": "python", 10 | "request": "launch", 11 | "program": "${file}", 12 | "console": "integratedTerminal" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /90. Setting workspace in VSC/python english files/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.linting.pylintEnabled": true, 3 | "python.linting.enabled": true 4 | } -------------------------------------------------------------------------------- /90. Setting workspace in VSC/python english files/sample.py: -------------------------------------------------------------------------------- 1 | print("sample") -------------------------------------------------------------------------------- /91. linters/python english files.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/91. linters/python english files.zip -------------------------------------------------------------------------------- /92. Debugging mode/sample.py: -------------------------------------------------------------------------------- 1 | 2 | from collections import Counter 3 | import random 4 | 5 | x = 0 6 | 7 | weaponChanceToHitPercentage = (input("Weapon percentage: ")) 8 | 9 | 10 | def will_weapon_hit(weaponChanceToHitPercentage): 11 | chanceToHit = random.uniform(0, 100) 12 | if (weaponChanceToHitPercentage > chanceToHit): 13 | return "hit" 14 | else: 15 | return "not hit" 16 | 17 | 18 | hitList = [] 19 | 20 | while x < 5: 21 | x = x + 1 22 | hitList.append(will_weapon_hit(weaponChanceToHitPercentage)) 23 | 24 | print(Counter(hitList)) 25 | -------------------------------------------------------------------------------- /93. Ligatures/Useful Resource Links.txt: -------------------------------------------------------------------------------- 1 | Useful Resource Links 2 | 3 | Cascadia Font: 4 | https://github.com/microsoft/cascadia-code 5 | 6 | Fira Code Download Link: 7 | https://github.com/tonsky/FiraCode -------------------------------------------------------------------------------- /94. Object oriented programming/oop-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/94. Object oriented programming/oop-source-codes.zip -------------------------------------------------------------------------------- /95. classes and objects/what-are-objects-classes-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/95. classes and objects/what-are-objects-classes-source-codes.zip -------------------------------------------------------------------------------- /96. methods and self/methods-self-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/96. methods and self/methods-self-source-codes.zip -------------------------------------------------------------------------------- /97. Constructor - init/constructor-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/97. Constructor - init/constructor-source-codes.zip -------------------------------------------------------------------------------- /98. EXERCISE - rockets/rockets-source-code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/98. EXERCISE - rockets/rockets-source-code.zip -------------------------------------------------------------------------------- /99. Docstring/docstring-source-codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/99. Docstring/docstring-source-codes.zip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Packt 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 | -------------------------------------------------------------------------------- /Quiz Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/Quiz Questions.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Python-for-Beginners-Learn-Python-from-Scratch 5 | Code repository for Python for Beginners: Learn Python from Scratch, published by Packt 6 | -------------------------------------------------------------------------------- /Retrievied missing items/EXERCISE - Absolute value of a number.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/Retrievied missing items/EXERCISE - Absolute value of a number.pdf -------------------------------------------------------------------------------- /Retrievied missing items/EXERCISE - Counting the sum of all arguments.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/Retrievied missing items/EXERCISE - Counting the sum of all arguments.pdf -------------------------------------------------------------------------------- /Retrievied missing items/EXERCISE - FileNotFoundError exception.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/Retrievied missing items/EXERCISE - FileNotFoundError exception.pdf -------------------------------------------------------------------------------- /Retrievied missing items/EXERCISE - filter pages to those that open and don't and save them in file.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/Retrievied missing items/EXERCISE - filter pages to those that open and don't and save them in file.pdf -------------------------------------------------------------------------------- /Retrievied missing items/Return & invoke.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/Retrievied missing items/Return & invoke.pdf -------------------------------------------------------------------------------- /Retrievied missing items/The most useful shortcuts used by programmers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-for-Beginners-Learn-Python-from-Scratch/2f15f470d20396d48b95ab33de4a01061ab587b8/Retrievied missing items/The most useful shortcuts used by programmers.pdf -------------------------------------------------------------------------------- /Retrievied missing items/opening_file.py: -------------------------------------------------------------------------------- 1 | 2 | def read_content_of_file(path): 3 | try: 4 | with open(path, "r", encoding="UTF-8") as file: 5 | return file.read() 6 | except FileNotFoundError: 7 | print("File not found, give a proper path") 8 | 9 | nameOfFile = input("Give me the name of file: ") 10 | 11 | fileContent = read_content_of_file(nameOfFile) 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------