{"id":23682608,"url":"https://github.com/makstyle119/python","last_synced_at":"2025-10-11T16:08:41.061Z","repository":{"id":269734955,"uuid":"907553886","full_name":"makstyle119/python","owner":"makstyle119","description":"Python from beginner to advanced ","archived":false,"fork":false,"pushed_at":"2025-02-03T18:54:17.000Z","size":46,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-28T22:04:12.376Z","etag":null,"topics":["begginer-friendly","makstyle119","python","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/makstyle119.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-23T21:21:35.000Z","updated_at":"2025-02-03T18:54:20.000Z","dependencies_parsed_at":"2025-02-19T20:42:43.421Z","dependency_job_id":"7e8e75f8-92e5-4e72-aa1b-6757d8e75fa0","html_url":"https://github.com/makstyle119/python","commit_stats":null,"previous_names":["makstyle119/python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/makstyle119/python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makstyle119%2Fpython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makstyle119%2Fpython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makstyle119%2Fpython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makstyle119%2Fpython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makstyle119","download_url":"https://codeload.github.com/makstyle119/python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makstyle119%2Fpython/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262352473,"owners_count":23297679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["begginer-friendly","makstyle119","python","tutorial"],"created_at":"2024-12-29T19:52:32.963Z","updated_at":"2025-10-11T16:08:36.002Z","avatar_url":"https://github.com/makstyle119.png","language":"Python","readme":"# python\n\nthis is my journey to learn and understand python\n\n## Run locally\n\nrun this and you all set to go\n```\ndocker compose run python-app\n```\n\n## Folder Structure:\n\n```\n├── 📂 lectures\n    ├── 📂 001\n        ├── 📄 basic.py\n├── 📂 projects\n    ├── 📂 001\n        ├── 📄 rock_paper_scissors_game.py\n    ├── 📂 002\n        ├── 📄 Card.py\n```\n\n## Code Explaining\n\n- lectures/001/basic.py\n    - `name = \"MAK\"` # this is how you define a variable in python - name and value\n    - `print(name)` # this is how you print a variable\n    - `type(name)` # this is how you know the type of a variable\n    - `isinstance(age, int)` # this is also you can check the type of a variable - it will return true or false\n    - their are various data types in `python`\n        - `name = \"MAK\"` # string\n            - string have few built in method\n                - `len()` # find the length of the string\n                - `.isalpha()` # check if all characters are alphabets return true or false\n                - `.isalnum()` # check if all characters are digits or not empty return true or false\n                - `.isdecimal()` # check if all characters are decimal return true or false\n                - `.upper()` # convert text into uppercase\n                - `.isupper()` # check if all characters are in uppercase return true or false\n                - `.lower()` # convert text into lowercase\n                - `.islower()` # check if all characters are in lowercase return true or false\n                - `.title()` # convert first character of each word capital\n                - `.startsswith()` # check if string start with a sub string return true or false\n                - `.endswith()` # check if string end with a sub string return true or false\n                - `.replace()` # replace the characters\n                - `.split()` # split a string on a specific character\n                - `.strip()` # to remove whitespace from a string\n                - `.join()` # to append a new letter into a string\n                - `.find()` # find the index of a substring\n        - `age = 23` # integer\n            - number have few built in method which will work all type of number (integer, decimal)\n                - `abs()` # this will return absolute number (remove negative sign)\n                - `round()` # convert .0-.4 to current number and .5-.9 to next number\n        - `height = 5.9` # float\n        - `is_student = True` # boolean\n        - `hobbies = [\"reading\", \"coding\", \"gaming\", \"sleeping\"]` # list - in other languages are array\n            - list have few built in method\n                - `in` - `print(\"coding\" in hobbies)` # this will return true or false and usually use in conditions\n                - `[]` - `hobbies[0]`  # this will return reading - this is how you can access value of a list by index\n                - `[]` - `hobbies[1:3]`  # this will return [\"coding\", \"gaming\"] - this will return data in range it will start with the first number index and end will one before last value index - and if first value is not define `hobbies[:3]` this will return data from 0 index to 2 index - and same way if last value is not provided `hobbies[1:]` this will return everything after the first index and first index is included\n                - `[]` - `hobbies[1:1] = ['something_new', 'learning]` # this will add the value of the new list before the selected index -  for this your both value of the range should be same - and in will add before the current index so if we add 2 then previous value index will be 3 and on 1 and 2 our newly added value will be added\n                - `insert(index, value)` # first value is the index where you want to add and second is the value which you want to add - so if you want to add fun in 1 index you will write something like this `hobbies.insert(1, \"fun\")`\n                - `.append(\"some_value\")` # this will add a new value in the list\n                - `.extend([\"some_other_value_1\", \"some_other_value_2\"])` # this will add new list inside the existing one\n                - `+= [\"some_other_value_1\", \"some_other_value_2\"]` # this will do the same thing as extend - add a new list inside the existing list\n                - `.remove(\"sleeping\")` # this will remove sleeping from the list - this way you can remove by value from a list - this course remove it from my life :-(\n                - `.pop()` # this will remove last value from the list\n                - `.sort()` # this will sort the list - only if data type is same of all the member of the list - it will do in ascending order - it will modified the existing list\n                    - first in uppercase then in lower case\n                - `len()` # find the length of the list\n                - `sorted(list, way_to_sort)` # this will take first argument as list and second argument as how you want to sort the list - it will not modified the existing list\n        - `address = { \"city\": \"Karachi\", \"country\": \"Pakistan\" }` # dictionary - in other language are object\n            - dictionary have few built in method\n                - `[key_name]` # you can write dictionary name with large bracket and inside large bracket you can provide any key name to get the value of that key - `address['city']` this will return we the name (value) of the key city which is karachi\n                - `.get(key_name)` # you can also get the value of an key by using this \n                    - only benefit is with .get you can get a default value so if value doesn't get it will return a default value\n                        - `address.get(\"region\", \"not provided\")` # it will return not provided if region is not their\n                - `.pop(key_name)` # you can delete any key from and dictionary by using this\n                - `.popitem()` # it will delete last inserted item from the dictionary\n                - `in` - `print(\"city\" in address)` # this will return true or false if key is present inside the dictionary and usually use in conditions                \n                - `.keys()` # it will return all the keys inside a list which is inside a dict_keys\n                    - use `list(address.keys())` to get only keys\n                - `.values()` # it will return all the values inside a list which is inside a dict_values\n                    - use `list(address.values())` to get only values\n                - `del dictionary[key_name]` # this will delete the key\n                - `del dictionary.key_name` # this will also delete the key\n                - `.copy()` # this will copy the entire dictionary\n                - `len()` # find the length of the address\n        - `complex(2, 3)` # for complex numbers\n            - `print(num2.real, num2.imag)` # this is how you can print the real and imaginary part of a complex number\n        - `programming_languages = (\"javascript\", \"php\", \"python\", \"c++\")` # tuples are same as list - first different we use round bracket in tuples while large bracket in list - second and most import value can't be change\n            - most of the functionality is same as list\n                - `in` - `print(\"python\" in programming_languages)` # this will return true or false and usually use in conditions\n                - `[]` - `programming_languages[0]`  # this will return javascript - this is how you can access value of a tuples by index\n                - `.index(\"c++\")` # this will return the index of the value - this is something we can't find in list\n                - `len()` # find the length of the tuples\n                - `[]` - `programming_languages[1:3]`  # this will return [\"coding\", \"gaming\"] - this will return data in range it will start with the first number index and end will one before last value index - and if first value is not define `programming_languages[:3]` this will return data from 0 index to 2 index - and same way if last value is not provided `programming_languages[1:]` this will return everything after the first index and first index is included\n                - as we know you can't add anything new inside a tuples but you can combine two two make one new one `new_tuples = old_tuples1 + old_tuples2`\n        - `range` # for ranges\n        - `friends = {\"Andomi\", \"Maria\"}` # sets are like list - first different they use curly bracket not large - second there will be no duplicated in the set\n            - one benefit sets have that they can behave like math sets so you can get\n                - `\u0026` # this will return same in both set - no duplicate\n                    - `set1 = {'Moiz', 'Maria'}; set2 = {'Moiz', 'Andomi'}; common = set1 \u0026 set2; print(common) # common will only have common things in both sets - no duplicate - which is {'Moiz'}\n                - `|` # this will return all the value - no duplicate\n                    - `set1 = {'Moiz', 'Maria'}; set2 = {'Moiz', 'Andomi'}; all = set1 | set2; print(all) # all will have all things in both sets - no duplicate - which is {'Moiz', 'Andomi', 'Maria'}\n                - `-` # this will return all the different in both sets - no duplicate\n                    - `set1 = {'Moiz', 'Maria'}; set2 = {'Moiz', 'Andomi'}; sub = set1 - set2; print(sub) # sub will have only the different things from first sets - no duplicate - which is {'Maria'}\n                - `\u003c` # check if first set is sub set of second - return true or false\n                    - `set1 = {'Moiz', 'Maria'}; set2 = {'Moiz', 'Andomi'}; res = set1 \u003c set2; print(res) # return true if second set all value will be present in first set otherwise return false\n                - `\u003e` # check if second set is sub set of second - return true or false\n                    - `set1 = {'Moiz', 'Maria'}; set2 = {'Moiz', 'Andomi'}; res = set1 \u003e set2; print(res) # return true if first set all value will be present in second set otherwise return false\n            - sets have few built in method\n                - `len()` # find the length of the sets\n    - their are 2 types of variables global variables and local variables\n        - global (out of function)\n        - local (inside a function)\n        - in simple if something inside a function can't be use outside but outside things can be use inside the functions\n    - this is how you can convert data type\n        - `int(\"20\")` # convert string to integer\n        - `float(19)` # convert integer to float\n        - `list(dictionary)` # convert dictionary into list - work with dictionary \n        - `list(set)` # convert set into list - work with set \n    - this is how you can concatenation\n        - `print(name + \" is \" + str(age) + \" years old.\")` # this is how you concatenate a string and a variable\n        - `print(f\"{name} is {age} years old.\")` # this is how you can also concatenate a string and a variable\n    - `class State(Enum):` # this is how you create an enum in python\n        - this is how you can access enum values\n            - `print(State.INACTIVE.value)` # this is how you can access the enum values\n            - `print(State['ACTIVE'].value)` # 1 - this is also how you can access the enum values\n        - enum have few built in method\n            - `list()` # this is how you can get the list of all the enum value\n            - `len()` # find the length of the enum\n    - you can use conditions useing if, elif and else\n        - `if answer == 1:` # this is how you can use if - we write the if keyword and then the condition\n        - `elif answer == 2:` # this is how you can use else if in python - we write the elif keyword and then the condition\n        - `else:` # this is how you can use else in python - it will run if none of the above conditions are true\n    - `input(\"Enter your age: \")` # this is how you can take input from the user - inside the input can be a string or empty\n    `def greet(name):` # this is how you can define a function\n        - we can pass function argument inside a function - inside the round bracket after function name and you have to use def before function to tell that it's a function\n        - a function can be void (not returning anything) or return any data type\n        - argument were use for dynamic content inside the function\n        - if you update an dictionary (which is an argument inside a function) when the value will be change globally\n        - to run a function you have to call it by typing function name with round bracket in the end - and if function have any parameters (function arguments call parameters) then pass then inside the round brackets - parameter can be any data types or any variable\n            - `greet(name)`\n        - function arguments can have default values so if function don't get any parameter we will use default value otherwise use provided value - after adding parameter you have to add is = and provide default value - default value is optional\n            - `def greet(name = \"user\"):`\n        - sometime there will be nester function - meaning function are inside a function and we call it nested functions\n        - `nonlocal time` # this is how you can access a variable from the outer function - nonlocal variable - in general you can't use a variable from the outer function inside a inner function\n        - closures - a closure is a function that remembers the values in enclosing scopes even if they are not present in memory (explain in code with example and code - lectures/001/basic.py:78 - lectures/001/basic.py:101)\n    - `object` # everything is a object in python just like in js\n        - object have few built in method (meaning you can use this with everything)\n            - `.bit_length()` # return the minimum bit required for the object to keep the value\n    - `loops` # we have 2 kind of loops in python\n        - we have few things in both loops common\n            - `continue` # this will break the current iteration and move to next\n            - `break` # it will break the loop entirely\n        - `while condition` # while loop will run until condition keep getting true\n            - `while condition == True:` # while loop - you can use a while loop when you don't know the number of iterations\n        - `for data in data_list` # for loop will run with the length of the list\n            - `for hobby in hobbies:` # this is how you can use a for loop in python - you can use a for loop when you know the number of iterations\n            - if you want to iterate x amount and if you know the time you can use `range(x)` to get the job done\n                - `for item in range(15)` # it will give a range from 0 to 15 - (0, 15)\n            - `enumerate(list)` # to get index with the value\n    - `class` # a class is a blueprint for creating objects\n        - `class Animal:` # this is how you can define a class - class name should be in CamelCase - just a standard\n            - function inside a class is called a method\n            - variables inside a class are called attributes\n        - `def __init__(self, name, age, color):` # this is how you can define a constructor - a constructor is a special method that is called when an object is created - name, age and color are the attributes of the class - self is mandatory other things are optional\n        - `def bark(self):` # this is how you can define a method - self is a reference to the current instance of the class\n        - `class Dog (Animal):` # this is how you can inherit a class - Dog is inheriting from Animal\n            - in inherit class will get everything from parent class\n        - `operation overloading` # you can define the behavior of the operators\n            - `def __gt__(self, other): return self.age \u003e other.age` \n                - `print(obj1 \u003e obj2)` # in this situation we will compare both ages or whatever we describe in the operation overloading\n            - there are few more operation we can use\n                - `__add__` # for +\n                - `__sub__` # for -\n                - `__mul__` # for *\n                - `__truediv__` # for /\n                - `__floordiv__` # for //\n                - `__mod__` # for %\n                - `__pow__` # for **\n                - `__rshift__` # for \u003e\u003e\n                - `__lshift__` # for \u003c\u003c\n                - `__and__` # for \u0026\n                - `__or__` # for |\n                - `__xor__` # for ^\n        - class have few built in method\n            - `type(class_instance/object)` # to check the class Name of the instance\n            - `isinstance(class_instance/object, class)` # first argument will be the object and second will be class and this will return if the object is a class or not (boolean)\n            - `issubclass(sub_class, class)` # first argument will be the sub_class and second will be class and this will return if the sub_class inherit from the class or not (boolean)\n    - `accepting command line arguments`\n        - `name = argv[1]` # this is how you can get the command line arguments - argv is a list of command line arguments - part of sys module - argv[0] is the name of the file - argv[1] is the first argument and so on\n    - `lambda num : num * 2` #  # this is how you can define a lambda function - lambda functions are anonymous functions - they are used when you need a function for a short period of time\n    - `map` # return a new list - with updated values\n    - `filter` # return a new list - return only the value where condition comes true\n    - `reduce`# use for calculation stuff\n    - `recursion` # recursion is calling function inside the function\n    - `@function_name` # decorators - you can add a decorator by adding @ and then function name before the function and when you call it the decorator function will run first\n    - `\"\"\" some stuff \"\"\"` # add anything inside this and it will become Docstring (description)\n        - `help(function_name)` # using help function you can help all the docstring related to the function\n    - annotations\n        - `some_other_name: string = \"MAK\"` # this is how you can define a variable with annotations\n        - `def some_function1(name: str, age: int) -\u003e str:` # this is how you can define a function with annotations - annotations are used to specify the type of the arguments and the return type of the function - inside function argument you can add column and then add data type you want and after round bracket ends you can add arrow -\u003e and define return data type\n    - exceptions\n        - this is how you can handle exceptions - try block is used to catch exceptions - except block is used to handle exceptions - finally block is used to run the code no matter what\n```\n# imports\n# this is how you import a module\nfrom enum import Enum\nfrom sys import argv\n\n# variables\n# this is how you define a variable - name and value\nname = \"MAK\" # string\nage = 23 # integer\nfloat_age = float(age) # convert integer to float\nheight = 5.9 # float\nis_student = True # boolean\nhobbies = [\"reading\", \"coding\", \"gaming\", \"sleeping\"] # list - can be of any type\naddress = { \"city\": \"Karachi\", \"country\": \"Pakistan\" } # dictionary\n\n# prints\n# this is how you print a variable\n# this is how you know the type of a variable\nprint(type(name)) \n# this is also you can check the type of a variable - it will return true or false\nprint(isinstance(age, int)) # True\n\n# this is how you concatenate a string and a variable\nprint(name + \" is \" + str(age) + \" years old.\")\n\n# this is how you can also concatenate a string and a variable\nprint(f\"{name.lower()} is {age} years old.\")\n\n# numbers\n# this is how you can get the real and imaginary part of a complex number\nnum1 = 2+3j\n# this is also how you can get the real and imaginary part of a complex number\nnum2 = complex(2, 3)\n# this is how you can print the real and imaginary part of a complex number\nprint(num2.real, num2.imag) # 2.0, 3.0\n\n# enums\n# this is how you create an enum\nclass State(Enum):\n    INACTIVE = 0\n    ACTIVE = 1\n\n# this is how you can access the enum values\nprint(State.INACTIVE.value) # 0\nprint(State['ACTIVE'].value) # 1 - this is also how you can access the enum values\nprint(list(State)) # this is how you can get the list of all the enum values\n\n# input\nage = input(\"Enter your age: \") # this is how you can take input from the user - inside the input can be a string or empty\nprint(f\"Your age is {age}\")\n\n# id else elif\nanswer = 1\n# this is how you can use if - we write the if keyword and then the condition\nif answer == 1:\n    print(\"answer is 1\")\n# this is how you can use else if - we write the elif keyword and then the condition\nelif answer == 2:\n    print(\"answer is 2\")\n# this is how you can use else - it will run if none of the above conditions are true\nelse:\n    print(\"answer is not 1 or 2\")\n\n# functions\n# this is how you can define a function\ndef greet(name):\n    # this is how you can define a variable inside a function - local variable\n    time = 10\n    # this is how you can define a function inside a function - this is a nested function\n    def get_greeting_from_time():\n        # this is how you can access a variable from the outer function - nonlocal variable - in general you can't use a variable from the outer function inside a inner function\n        nonlocal time\n        return \"Good Morning\" if 0 \u003c= time else \"Good Evening\"\n    print(f\"{get_greeting_from_time()}, Hello {name}\")\n\n# this is how you can call a function\ngreet(name)\n\n# closures\n# this is how you can create a closure - a closure is a function that remembers the values in enclosing scopes even if they are not present in memory\ndef parent_function(person):\n    # this is how you can define a variable inside a function - local variable\n    coin = 3\n    # this is how you can define a function inside a function - this is a nested function\n    def coin_management():\n        # this is how you can access a variable from the outer function - nonlocal variable - in general you can't use a variable from the outer function inside a inner function\n        nonlocal coin\n        coin -= 1\n        if coin \u003e 0:\n            print(f\"{person} has {coin} left\")\n        else:\n            print(f\"{person} is out of coin\")\n    return coin_management\n    \nson = parent_function(\"son\")\ndaughter = parent_function(\"daughter\")\n\nson() # son has 2 left\nson() # son has 1 left\ndaughter() # daughter has 2 left\nson() # son is out of coin\ndaughter() # daughter has 1 left\n\n# loops\n# this is how you can use a for loop\ncondition = True\n# while loop - you can use a while loop when you don't know the number of iterations\nwhile condition == True:\n    print(\"condition is true\")\n    condition = False\n\n# this is how you can use a for loop - you can use a for loop when you know the number of iterations\nfor hobby in hobbies:\n    print(hobby)\n\n# Class\nclass Animal:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n    \n    def get_name(self):\n        return self.name\n# this is how you can define a class - a class is a blueprint for creating objects - class name should be in CamelCase - just a standard\n# this is how you can inherit a class - Dog is inheriting from Animal\nclass Dog (Animal):\n    # function inside a class is called a method\n    #  variables inside a class are called attributes\n\n    # this is how you can define a constructor - a constructor is a special method that is called when an object is created - name, age and color are the attributes of the class\n    def __init__(self, name, age, color):\n        self.name = name\n        self.age = age\n        self.color = color\n    # operation overloading - you can define the behavior of the operators\n    def __gt__(self, other):\n        return self.age \u003e other.age\n\n    # this is how you can define a method - self is a reference to the current instance of the class\n    def bark(self):\n        print(\"Woof\")\n\n# this is how you can create an object of a class - you have to provide the required arguments\ntommy = Dog(\"tommy\", 2, \"brown\") # this is how you can create an object of a class\ntommy.bark() # this is how you can call a method of a class\nprint(tommy.name) # this is how you can access the attributes of a class\n\n# accepting command line arguments\nname = argv[1] # this is how you can get the command line arguments - argv is a list of command line arguments - part of sys module - argv[0] is the name of the file - argv[1] is the first argument and so on\nprint(f\"Hello {name}\")\n\n# lambda functions\nlambda num : num * 2 # this is how you can define a lambda function - lambda functions are anonymous functions - they are used when you need a function for a short period of time\n\n# recursion - a function calling itself\ndef factorial(n):\n    if n == 0:\n        return 1\n    return n * factorial(n - 1)\n\nprint(factorial(5)) # 120\n\n# annotations\n# this is how you can define a function with annotations - annotations are used to specify the type of the arguments and the return type of the function - inside function argument you can add column and then add data type you want and after round bracket ends you can add arrow -\u003e and define return data type\ndef some_function1(name: str, age: int) -\u003e str:\n    return f\"{name} is {age} years old.\"\n\nsome_other_name: string = \"MAK\" # this is how you can define a variable with annotations\n\n# exceptions\n# this is how you can handle exceptions - try block is used to catch exceptions - except block is used to handle exceptions - finally block is used to run the code no matter what\ntry:\n    # this is how you can raise an exception\n    raise Exception(\"This is an exception\")\nexcept Exception as e:\n    print(e)\nfinally:\n    print(\"This will run no matter what\")\n```\n\n- projects/001/rock_paper_scissors_game.py\n    - `import random` # this is how you import a module in python\n    - `def greeting():` # def is use for function in python\n    - `player_choice = 'rock'` # this is how you define a variable in python - name and value\n    - `player_choice = input()` # this is how you get input from the user in python\n    - `random.choice(OPTIONS)` # this is how you generate a random number in python - random.choice() - this will pick a random element from the list\n    - `choices = { \"player\": 'rock', \"computer\": 'paper' }` # this is how you define a dictionary in python - dictionary is like object in js and keep key value pair - name and value\n    - `print(f\"Player chose: {player}\")` # this is how you print a string in python - f\"\" - this is called f-string\n    - `def check_win(player, computer):` # that's how you can add arguments to a function in python\n    - `greeting()` # this is how you call a function in python - name of the function followed by ()\n    - `player, computer = selected_choices.values()` # this is how you can unpack a dictionary in python\n```\nimport random # this is how you import a module in python\n\nOPTIONS = [\"rock\", \"paper\", \"scissors\"]\n\n# def is use for function in python\ndef greeting():\n    print(\"Welcome to the Rock, Paper, Scissors game!\")\n    print(\"Please choose one of the following:\")\n    print(\"rock\")\n    print(\"paper\")\n    print(\"scissors\")\n\ndef get_choices():\n    # this is how you define a variable in python - name and value\n    # this is how you get input from the user in python\n    player_choice = input()\n    # this is how you generate a random number in python - random.choice() - this will pick a random element from the list\n    computer_choice = random.choice(OPTIONS)\n\n    # this is how you define a dictionary in python - dictionary is like object in js and keep key value pair - name and value\n    choices = {\n        \"player\": player_choice,\n        \"computer\": computer_choice\n    }\n\n    return choices\n\ndef print_choices(player, computer):\n    # this is how you print a string in python - f\"\" - this is called f-string\n    print(f\"Player chose: {player}\")\n    print(f\"Computer chose: {computer}\")\n\n# that's how you can add arguments to a function in python\ndef check_win(player, computer):\n    if player == computer:\n        print(\"It's a tie!\")\n    elif player == \"rock\":\n        if computer == \"paper\":\n            print(\"Computer wins!\")\n        else:\n            print(\"Player wins!\")\n    elif player == \"paper\":\n        if computer == \"scissors\":\n            print(\"Computer wins!\")\n        else:\n            print(\"Player wins!\")\n\n# this is how you call a function in python - name of the function followed by ()\ngreeting()\nselected_choices = get_choices()\n# this is how you can unpack a dictionary in python\nplayer, computer = selected_choices.values()\nprint_choices(player, computer)\ncheck_win(player, computer)\n```\n\n- projects/002/Card.py\n```\nclass Card:\n    def __init__(self, suit, rank):\n        self.suit = suit\n        self.rank = rank\n    \n    def __str__(self): # this will overwrite print functions\n        return (f\"{self.rank['rank']} of {self.suit}\")\n```\n\n- projects/002/Deck.py\n```\nfrom Card import Card\nimport random\n\nclass Deck:\n    def __init__(self):\n        self.cards = []\n        suits = [\"hearts\", \"diamonds\", \"clubs\", \"spades\"]\n        ranks = [\n            {\"rank\": \"A\", \"value\": 11},\n            {\"rank\": \"2\", \"value\": 2},\n            {\"rank\": \"3\", \"value\": 3},\n            {\"rank\": \"4\", \"value\": 4},\n            {\"rank\": \"5\", \"value\": 5},\n            {\"rank\": \"6\", \"value\": 6},\n            {\"rank\": \"7\", \"value\": 7},\n            {\"rank\": \"8\", \"value\": 8},\n            {\"rank\": \"9\", \"value\": 9},\n            {\"rank\": \"J\", \"value\": 10},\n            {\"rank\": \"Q\", \"value\": 10},\n            {\"rank\": \"K\", \"value\": 10}\n        ]\n        self.create_cards(suits, ranks)\n\n    def create_cards(self, suits, ranks):\n        for suit in suits:\n            for rank in ranks:\n                self.cards.append(Card(suit, rank))  # Use a tuple instead of a list for better readability\n\n    def shuffle(self):\n        if len(self.cards) \u003e 1:\n            random.shuffle(self.cards)\n\n    def deal(self, number=1):\n        card_dealt = []\n        for _ in range(number):\n            if len(self.cards) \u003e 0:  # Check if there are cards left to deal\n                card_dealt.append(self.cards.pop())\n            else:\n                break  # Exit if there are no cards left\n        return card_dealt\n```\n\n- projects/002/Hand.py\n```\nclass Hand:\n    def __init__(self, dealer = False):\n        self.cards = []\n        self.value = 0\n        self.dealer = dealer\n\n    def add_card(self, card_list):\n        self.cards.extend(card_list)\n\n    def calculate_value(self):\n        self.value = 0\n        has_ace = False\n\n        for card in self.cards:\n            card_value = int(card.rank[\"value\"])\n            self.value += card_value\n            if card.rank[\"rank\"] == \"A\":\n                has_ace = True\n\n        if has_ace and self.value \u003e 21:\n            self.value -= 10\n        \n    def get_value(self):\n        self.calculate_value()\n        return self.value\n    \n    def is_blackjack(self):\n        return self.get_value() == 21\n    \n    def display(self, show_all_dealer_cards = False):\n        print(f'''{\"Dealer's\" if self.dealer else \"Your\"} hand''')\n        for index, card in enumerate(self.cards):\n            if index == 0 and self.dealer and not show_all_dealer_cards and not self.is_blackjack():\n                print(\"hidden\")\n            else:\n                print(card)\n            print(card)\n\n        if not self.dealer:\n            print(f\"Value: {self.get_value()}\")\n        print()\n```\n\n- projects/002/Game.py\n```\nfrom Deck import Deck\nfrom Hand import Hand\n\nclass Game:\n    def play(self):\n        game_number = 0\n        games_to_play = 0\n\n        while games_to_play \u003c= 0:\n            try:\n                games_to_play = int(input(\"how many games do you want to play? \"))\n            except:\n                print(\"You must enter an number.\")\n\n        while game_number \u003c games_to_play:\n            game_number += 1\n\n            deck = Deck()\n            deck.shuffle()\n            \n            player_hand = Hand()\n            dealer_hand = Hand(dealer = True)\n\n            for i in range(2):\n                player_hand.add_card(deck.deal())\n                dealer_hand.add_card(deck.deal())\n\n            print()\n            print(\"*\" * 30)\n            print(f\" Game {game_number} of {games_to_play} \")\n            print(\"*\" * 30)\n            player_hand.display()\n            dealer_hand.display()\n\n            if self.check_winner(player_hand, dealer_hand):\n                continue\n\n            choice = \"\"\n            while player_hand.get_value() \u003c 21 and choice not in ['s', 'stand']:\n                choice = input(\"Please choose 'Hit' or 'Stand': \").lower()\n                print()\n                while choice not in [\"h\", \"s\", \"hit\", \"stand\"]:\n                    choice = input(\"Please enter 'Hit' or 'Stand' (or H/S) \").lower()\n                    print()\n                if choice in [\"h\", \"hit\"]:\n                    player_hand.add_card(deck.deal())\n                    player_hand.display()\n\n            if self.check_winner(player_hand, dealer_hand):\n                continue\n\n            player_hand_value = player_hand.get_value()\n            dealer_hand_value = dealer_hand.get_value()\n\n            while dealer_hand_value \u003c 17:\n                dealer_hand.add_card(deck.deal())\n                dealer_hand_value = dealer_hand.get_value()\n\n            dealer_hand.display(show_all_dealer_cards = True)\n\n            if self.check_winner(player_hand, dealer_hand):\n                continue\n\n            print(\"Final Results\")\n            print(f\"Your hand: {player_hand_value}\")\n            print(f\"Dealer hand: {dealer_hand_value}\")\n\n            self.check_winner(player_hand, dealer_hand, game_over = True)\n        \n        print(\"\\n Thanks For Playing!\")\n    \n    def check_winner(self, player_hand, dealer_hand, game_over = False):\n        if not game_over:\n            if player_hand.get_value() \u003e 21:\n                print(\"You busted. Dealer Wins!\")\n                return True\n            elif dealer_hand.get_value() \u003e 21:\n                print(\"Dealer busted. You win!\")\n                return True\n            elif dealer_hand.is_blackjack() and player_hand.is_blackjack():\n                print(\"Both players have blackjack! Tie!\")\n                return True\n            elif dealer_hand.is_blackjack():\n                print(\"Dealer win. Dealer have a blackjack!\")\n                return True\n            elif player_hand.is_blackjack():\n                print(\"You Win. You have a blackjack!\")\n                return True\n        else:\n            if player_hand.get_value() \u003e dealer_hand.get_value():\n                print(\"You win!\")\n            elif dealer_hand.get_value() \u003e player_hand.get_value():\n                print(\"Dealer win!\")\n            elif player_hand.get_value() == dealer_hand.get_value():\n                print(\"Tie!\")\n            return True\n        return False\n```\n\n- projects/002/main.py\n```\nfrom Game import Game\n\ng = Game()\ng.play()\n```\n\n## Logical Operators\n- `+` = for addition\n- `-` = for subtraction\n- `*` = for multiplication\n- `/` = for division\n- `%` = for mod (remainder)\n- `**` = for double multiplication\n- `//` = for division and then round to smallest\n- `==` = for comparison\n- `and` = and operator\n- `or` = or operator\n- `in` = in operator\n- `!` = not comparison\n- `\u003c` = less then comparison\n- `\u003c=` = less then and equal comparison\n- `\u003e` = greater then comparison\n- `\u003e=` = greater then and equal comparison\n\n## Keywords\n- `def` = use for function declaration\n- `input` = use to get user input\n- `print` = use to display data in console - just like console.log in js\n\n## Style Guide\n- `#` - this is a single line comment = use for single line comments\n- Python is caseSensitive, means name and Name are two other things - `kabab case` is recommended in python, eg: my_app.\n- In Python indentation is very important so don't mess with it otherwise you will be mess\n\n## Resources\nI start my journey using this cool stuff so shout to them:\n- https://www.youtube.com/watch?v=eWRfhZUzrAc\u0026t=12581s\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakstyle119%2Fpython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakstyle119%2Fpython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakstyle119%2Fpython/lists"}