{"id":22425228,"url":"https://github.com/aamnah/ttc2030-basics-of-programming","last_synced_at":"2025-06-11T08:38:38.414Z","repository":{"id":225884244,"uuid":"767129622","full_name":"aamnah/ttc2030-basics-of-programming","owner":"aamnah","description":"Exercises for the course Basics of Programming [TTC2030-3043]","archived":false,"fork":false,"pushed_at":"2024-03-04T18:59:10.000Z","size":1385,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-15T06:53:13.535Z","etag":null,"topics":["programming","python"],"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/aamnah.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}},"created_at":"2024-03-04T18:54:24.000Z","updated_at":"2024-03-04T18:56:43.000Z","dependencies_parsed_at":"2024-03-04T20:15:52.646Z","dependency_job_id":"67b8336a-00da-4ab0-8396-f148f972ae49","html_url":"https://github.com/aamnah/ttc2030-basics-of-programming","commit_stats":null,"previous_names":["aamnah/ttc2030-basics-of-programming"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aamnah%2Fttc2030-basics-of-programming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aamnah%2Fttc2030-basics-of-programming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aamnah%2Fttc2030-basics-of-programming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aamnah%2Fttc2030-basics-of-programming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aamnah","download_url":"https://codeload.github.com/aamnah/ttc2030-basics-of-programming/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228356402,"owners_count":17907191,"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":["programming","python"],"created_at":"2024-12-05T19:13:34.980Z","updated_at":"2024-12-05T19:13:35.600Z","avatar_url":"https://github.com/aamnah.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Basics Of Programming\n\nClass is a type, and an Object is in memory.\n\n\n### VS Code settings for Python\n\nSet Default Formatter and Tab Size 4\n```json\n  \"[python]\": {\n    \"editor.tabSize\": 4,\n    \"editor.formatOnType\": true,\n    \"editor.formatOnSave\": true,\n    \"editor.wordBasedSuggestions\": false,\n    \"diffEditor.ignoreTrimWhitespace\": false,\n    \"editor.defaultFormatter\": \"ms-python.python\",\n  }\n```\n\n### Documenting Python Code\n\nA string literal placed directly below the object can serve as documentation. [Read more](https://realpython.com/documenting-python-code/)\n\n```py\ndef plus_one(x):\n    \"\"\"purpose of this function is to increase the given parameter by one\n    \n    Parameters\n    ----------\n    x : int\n      a numeric value that will be increased by one\n\n    Returns\n    -------\n    int\n      increases value of parameter 'x' by one and returns the result\n    \"\"\"\n    result = x + 1\n    print(result)\n    return result\n\nplus_one(99)\n```\n\n## Variables\n\nVariable names can NOT\n- start with a number (e.g. `1msg`)\n- have a space in the name (e.g. 'super msg')\n- have a '-' in the name (e.g. 'super-msg')\n\nYou can not declare a variable without initializing it. For example:\n\nThis is fine:\n\n```py\nsuper_msg = 'Amna is super'\n```\n\nWhile this is not:\n\n```py\nsuper_msg\n\nsuper_msg = 'Amna is super'\n```\n\nQ: If you have multiple values for the same variable, what will happen? \nA: The last one will overwrite the one before\n\n## Conditions\n\n```py\nnumber2 = int(input(\"Gimme a number: \"))\nif number2 == 10:\n    print(\"number is 10\")\nelif number2 \u003c 10:\n    print(\"Number is less than 10\")\nelif number2 \u003e= 20:\n    print(\"Number is greater than or equal to 20\")\nelse:\n    print(\"Number is in between 11 and 19\")\n```\n\nhaving the statements on the same line is also valid, but you can not have `if` and `else` on the same line\n\n```py\n# having them on the same line is also valid\nnumber2 = int(input(\"Gimme a number: \"))\nif number2 == 10: print(\"number is 10\")\nelif number2 \u003c 10: print(\"Number is less than 10\")\nelif number2 \u003e= 20: print(\"Number is greater than or equal to 20\")\nelse: print(\"Number is in between 11 and 19\")\n```\n\nYou can also have `not` in `if` statements\n\n```py\nnumber2 = int(input(\"Gimme a number: \"))\nif not number2 == 10: print(\"number is not 10\")\nelif not number2 \u003c 10: print(\"Number is not less than 10\")\nelif number2 \u003e= 20: print(\"Number is greater than or equal to 20\")\nelse: print(\"Number is in between 11 and 19\")\n```\n\n## Logical operations\n```\nOR\n1010\n0101\n\n= 1111\n```\n\n```\nAND\n1010\n0101\n\n= 0000\n```\n\n```\nXOR (NOT OR / Exclusive OR)\n1010\n0101\n\n= 0000\n```\n\n## Collections\n\n```py\n# List\nnamelist = [\"Joe\", \"Sally\", \"Liam\", \"Robert\", \"Emma\", \"Isabella\"]\n\n# Tuple\n# read-only\nnametuple = (\"Joe\", \"Sally\", \"Liam\", \"Robert\", \"Emma\", \"Isabella\")\nsingle_nametuple = (\"Joe\",)\n\n# Set\n# no order or index, no duplicates\n# can not edit items, but can add/delete\nnameset = {\"Joe\", \"Sally\", \"Liam\", \"Robert\", \"Emma\", \"Isabella\"}\n\n# Dictionary\n# Key-value pair collection\nbookdict = {\n    12345678: \"Book 1\",\n    12345679: \"Book 2\",\n    12345680: \"Book 3\",\n    12345681: \"Book 4\",\n    12345682: \"Book 5\",\n}\n```\n\n\n### Set\nNo order of items, which means there is no index\n\n## Class\n\nClass constructor\n\n```python\n  # this is a constructor, it has a special name\n  # in Python the very first param must be self\n  def __init__(self, make = '',  model = '', engine_cc = 0, power_kw = 0):\n    self.make = make\n    self.model = model\n    self.engine_cc = engine_cc\n    self.power_kw = power_kw\n```\n\n### Converting an Array to a String\n\n```py\nnum = [2,7,12,19,27,33,38]\n\nprint(\" \".join(str(e) for e in num)) # 2 7 12 19 27 33 38\nprint(\",\".join(str(e) for e in num)) # 2,7,12,19,27,33,38\n```\n\n## Exceptions\nExeptions let you move on with your code instead of crashing. You `try` and if that doesn't work, it goes to the `exception`, where you can _handle_ it.\n\nFor example, when input is not given in the right format, tell the user with an exception.\n\n```py\ndef ask_number(prompt):\n  try:\n    number = int(input(prompt))\n  except:\n    print('Not a number')\n  return number\n\nask_number('Gimme a number: ')\n```\n\n## Doing maths in Python\n[read more on Using Python as a Calculator](https://docs.python.org/3/tutorial/introduction.html#using-python-as-a-calculator)\n\nRounding decimal places\n- [How can I format a decimal to always show 2 decimal places?](https://stackoverflow.com/questions/1995615/how-can-i-format-a-decimal-to-always-show-2-decimal-places)\n- [Limiting floats to two decimal points](https://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points/6539677#6539677)\n- round(float_num, num_of_decimals)\n\n- subtracting floats gives a float with a lot of decimal points (16)\n- division always returns a float\n\n```py\n# Subtracting floats\n13.9 - 2.3 = 11.600000000000001\n12.4 - 8.0 = 4.4\n12.4 - 8.1 = 4.300000000000001\n```\n\n```py\n# Division\n9 / 3 = 3.0\n5 / 2 = 2.5\n5 / 3 = 1.6666666666666667\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faamnah%2Fttc2030-basics-of-programming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faamnah%2Fttc2030-basics-of-programming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faamnah%2Fttc2030-basics-of-programming/lists"}