-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKaggle_python
More file actions
1 lines (1 loc) · 8.2 KB
/
Copy pathKaggle_python
File metadata and controls
1 lines (1 loc) · 8.2 KB
1
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":30684,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Hello, Pyhon\n\nprint('hello world')\n\nspam_amount = 10\nprint(spam_amount)\n\nspasm_amount = spam_amount+10\nprint(spam_amount)\n\nif(spam_amount == 0):\n print(\"i don't have any spam amount\")\nelse:\n print(\"I have some spam amount\")\n \nviking_song = \"Spam -> \" * spam_amount\nprint(viking_song)\n\nprint(5 / 2)\n\n# numbers and arithmetic in python\n\nf2_num = 14.98\ntype(f2_num)\n\nprint(8 - 3 + 2)\nprint(-5 + 4 * 2)\n\nhat_height_cm = 30\nmy_height_cm = 190\ntotal_height_meters = (hat_height_cm + my_height_cm) / 100\nprint(\"total height in meters: \", total_height_meters, \"m\")\n\n# using f-strings\nprint(f\"toal heignt in meters {total_height_meters:.1f}m\")\n\n# min, max and absolute values\nprint(min(1, 2, 3))\nprint(max(56, 78, 90))\n\nprint(abs(-5))\n\n# data types conversion - int, float, str\nprint(int(10.23))\nprint(float(111))\n\nprint(int(\"111\") + 23)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","scrolled":true,"execution":{"iopub.status.busy":"2024-04-13T09:29:55.409846Z","iopub.execute_input":"2024-04-13T09:29:55.410832Z","iopub.status.idle":"2024-04-13T09:29:55.419647Z","shell.execute_reply.started":"2024-04-13T09:29:55.410789Z","shell.execute_reply":"2024-04-13T09:29:55.418665Z"},"trusted":true},"execution_count":35,"outputs":[{"name":"stdout","text":"hello world\n10\n10\nI have some spam amount\nSpam -> Spam -> Spam -> Spam -> Spam -> Spam -> Spam -> Spam -> Spam -> Spam -> \n2.5\n7\n3\ntotal height in meters: 2.2 m\ntoal heignt in meters 2.2m\n1\n90\n5\n10\n111.0\n134\n","output_type":"stream"}]},{"cell_type":"code","source":"# python functions\nhelp(round)\n\ndef least_difference(a, b, c):\n '''\n returns the smallest difference between any two numbers\n '''\n diff1 = abs(a - b)\n diff2 = abs(b - c)\n diff3 = abs(a - c)\n least_diff = min(diff1, diff2, diff3)\n \n return least_diff\nprint(least_difference(45, 67, 21), \" and \",least_difference(82, 74, 91))\n\n# docstring = a string that explains the function\n\nhelp(least_difference)\n\nhelp(print)\nprint(1, 2, 3, 4, sep=\" -> \")\n\ndef greet(who='susan'):\n print(f\"hello, {who}\")\n \ngreet(who='Mohit')\n\ndef sum(x, y):\n return f\"the sum is {x + y}\" # x + y\nprint(sum(34, 98))\n\n# functions applied to functions....\ndef plus_five(x):\n return x + 5\n\ndef call(fn, arg):\n '''call function fn on arg'''\n return fn(arg)\n\ndef add_by_five(fn, org):\n return fn(fn(org))\n\nprint(call(plus_five, 5),add_by_five(plus_five, 5), sep=\"\\n\")\n# functions that operates on other functions are called higher order functions\n\ndef mod_5(x):\n return x % 5\n\nprint(max(23, 39, 92, key=mod_5))\n","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-04-13T15:42:14.027015Z","iopub.execute_input":"2024-04-13T15:42:14.027541Z","iopub.status.idle":"2024-04-13T15:42:14.044775Z","shell.execute_reply.started":"2024-04-13T15:42:14.027494Z","shell.execute_reply":"2024-04-13T15:42:14.043573Z"},"trusted":true},"execution_count":34,"outputs":[{"name":"stdout","text":"Help on built-in function round in module builtins:\n\nround(number, ndigits=None)\n Round a number to a given precision in decimal digits.\n \n The return value is an integer if ndigits is omitted or None. Otherwise\n the return value has the same type as the number. ndigits may be negative.\n\n22 and 8\nHelp on function least_difference in module __main__:\n\nleast_difference(a, b, c)\n returns the smallest difference between any two numbers\n\nHelp on built-in function print in module builtins:\n\nprint(...)\n print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n \n Prints the values to a stream, or to sys.stdout by default.\n Optional keyword arguments:\n file: a file-like object (stream); defaults to the current sys.stdout.\n sep: string inserted between values, default a space.\n end: string appended after the last value, default a newline.\n flush: whether to forcibly flush the stream.\n\n1 -> 2 -> 3 -> 4\nhello, Mohit\nthe sum is 132\n10\n15\n39\n","output_type":"stream"}]},{"cell_type":"code","source":"# Booleans and conditionals in python\n\nans = True\n# print(ans)\n\ndef can_run_for_president(age, is_natural_born_citizen):\n if(age >= 35 and is_natural_born_citizen.lower() == \"yes\"):\n return True\n else:\n return False\n \nprint(can_run_for_president(31, \"yes\"))\n\nprint(\"is equal:\", 3.0 == '3')\n\ndef is_odd(num):\n return num % 2 == 1\nprint(\"Is 3 odd?\", is_odd(3))\nprint(\"Is 4 odd?\", is_odd(4))\n\n# combine boolean values: and, or, not\n\ndef is_indian(aadhar_card, birth_certificate):\n if(aadhar_card.lower() == \"yes\" or birth_certificate.lower() == \"yes\"):\n return \"maybe he is Indian\"\n elif(aadhar_card.lower() == \"yes\" and birth_certificate.lower() == \"yes\"):\n return \"he is Indian, Confirmed!\"\n else:\n return \"he is not Indian\"\n \nprint(is_indian(\"yes\", \"no\"))\n\nTrue or True and False\n\n# boolean conversion\n# all strings are treated as true except the empty string\nprint(bool(\"\"))\nprint(bool(\"hello\"))\nprint(bool(1))","metadata":{"execution":{"iopub.status.busy":"2024-04-13T16:32:40.586166Z","iopub.execute_input":"2024-04-13T16:32:40.586547Z","iopub.status.idle":"2024-04-13T16:32:40.595563Z","shell.execute_reply.started":"2024-04-13T16:32:40.586518Z","shell.execute_reply":"2024-04-13T16:32:40.594681Z"},"trusted":true},"execution_count":60,"outputs":[{"name":"stdout","text":"False\nis equal: False\nIs 3 odd? True\nIs 4 odd? False\nmaybe he is Indian\nFalse\nTrue\nTrue\n","output_type":"stream"}]},{"cell_type":"code","source":"# lists in python\nitems = [1, \"dog\", 3.14, True, [1, 2, 3]]\n# print(items)\nfor item in items:\n print(item)\n \n\n# list of lists\nmatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\nprint(matrix[0][1])\n\nplanets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\nprint(len(planets))\n\n# print last element\nprint(planets[-1])\n\n# slicing\nprint(planets[0:3])\nprint(planets[3:])\n\n# all the planets except the first and last\nprint(planets[1:-1])\n# remove first 2 and last 3\nprint(planets[2:-3])\n\n# the last three planets\nprint(planets[-3:])\n\n# lists are mutable and can be modified\nplanets[3] = 'Moon'\nplanets\n\n# sorting in lists\nsorted(planets)\n\n# sum of numbers in lists\nprimes = [2, 3, 5, 7]\nsum(primes)\nmax(primes)\n\n# objects: a method is a function that belongs to an object\nx = 12\nprint(x.imag)\nprint(x.bit_length())\n\nplanets.append(\"Pluto\")\nplanets[3] = \"mars\"\nplanets\n\n# list.pop() removes the last element in the list\nplanets.pop()\n\n# search index of an element\nplanets.index(\"Jupiter\")\n\nprint(\"Jupiter\" not in planets)\n\n# Tuple - immutable lists or cannot be modified\n\nt = (1, 2, 3, \"hello\", 2)\nt","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-04-13T18:43:22.634809Z","iopub.execute_input":"2024-04-13T18:43:22.635162Z","iopub.status.idle":"2024-04-13T18:43:22.649415Z","shell.execute_reply.started":"2024-04-13T18:43:22.635136Z","shell.execute_reply":"2024-04-13T18:43:22.648349Z"},"trusted":true},"execution_count":38,"outputs":[{"name":"stdout","text":"1\ndog\n3.14\nTrue\n[1, 2, 3]\n2\n8\nNeptune\n['Mercury', 'Venus', 'Earth']\n['Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n['Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus']\n['Earth', 'Mars', 'Jupiter']\n['Saturn', 'Uranus', 'Neptune']\n0\n4\nFalse\n","output_type":"stream"},{"execution_count":38,"output_type":"execute_result","data":{"text/plain":"(1, 2, 3, 'hello', 2)"},"metadata":{}}]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}