Created
February 21, 2018 21:21
-
-
Save ischurov/be7e558d632c242b56deeac10e36096f to your computer and use it in GitHub Desktop.
Python ICEF 2018, Lecture 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# Anaconda Python 3.6\n# Sage Cloud\nprint(2 + 3)", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "5\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 10", | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(x)", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "10\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(x + 1)", | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "11\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "фыва = 12\nпролдж = 20\nprint(фыва + пролдж)", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "32\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "type(10)", | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "int" | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "type(x)", | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "int" | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = x / 2", | |
"execution_count": 12, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x", | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "5.0" | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "type(x)", | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "float" | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "13 // 2", | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "6" | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "13 % 3", | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "1" | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "7 ^ 2", | |
"execution_count": 17, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "5" | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "5 ^ 3", | |
"execution_count": 18, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "6" | |
}, | |
"execution_count": 18, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "5 ** 3", | |
"execution_count": 19, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "125" | |
}, | |
"execution_count": 19, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "123 ** 1237", | |
"execution_count": 23, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "163163439059267607766412588358432720764705585651376777801072556931204787091754549301755268283813502170051856836680873868228125359931910185967884141024967430197994038178708872718306208290447758206889637182108748411903369547519160564574335039394649337847229729467181183283493552600023531977565461283740514523594929951230900918463896917693073750482004634784484650871409384367944004652198870079831873381976275579136398611523067002670179788326213613911587642552434426112669778416252890947194388388373589703361171183806894622985557865715338233327379829792369623292283207756724423169460076436853502321387040596879585083939223070286630378267368024534573120185449041159999021346351276303365557997666213823859665709424065889684161207276180024239065678637095114164654748797822860718722833019070562280005417912154061405363995749633122389584067690180973844335732790462475178434080478468662646080813914320852933004970659281654210897477595619827698883861454423138500083404191321166585164643487874242381490489378262729439077616991592788720182347951700470672999729941231780959895106061473103912055116057262453888844248880819777672040817565683761418332366238666972221902799822378218812501471496123966365548081264116879031509627700145165440364783596733159882690347400078514050542007655584746205237361154629037274677394603499336197693256816564464104928867652395220247492121865022559480785812811819578740374262094522283711766337360396638515867495449398141460388495996675408468363637963127139917545210555753963983995383041509273746112062320769080641564355656252272888174786766454371097708423151002897775496233662523752177342422606841426970886561734460149383584606785394262217985363534134675066919104265496336256595768786243969452867099151194514806954322894053005061644899384294101444973653564402661781481026503980438909167191304492751069660241883899394311836979854218730944666928269875212030382724895293929807582787923983972052383831536514697439364764872327843723670925762770612293887630491275121986026197403740417794740897572130505888792228202905246577737077348147151311915174115671551090626882976769118975110392097983601973419815407198095031730489412188380437918911517136879030537071434718326132729541335921589361096227649831933753831199091814600736494284471976090350542048925926768231575632195589993873142198179552898927437383533873544673646435022014135057233647477546035926427792862450414267230162669315167612414324032551661501419252305974569320840025683561560319698727890410218236771540636103617690626117086903671091096334978494639680930124033624610633893733202256093892564661171418593399070850003403403" | |
}, | |
"execution_count": 23, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "123. ** 1237.", | |
"execution_count": 22, | |
"outputs": [ | |
{ | |
"ename": "OverflowError", | |
"evalue": "(34, 'Result too large')", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mOverflowError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-22-10b5c1c7e341>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m123.\u001b[0m \u001b[0;34m**\u001b[0m \u001b[0;36m1237.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mOverflowError\u001b[0m: (34, 'Result too large')" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = \"Hello, World!\"", | |
"execution_count": 24, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "w = 'Another test'", | |
"execution_count": 25, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "\"'\"", | |
"execution_count": 26, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "\"'\"" | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "\"\\\"\\'\"", | |
"execution_count": 27, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'\"\\''" | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(\"Hello\\nWorld!\")", | |
"execution_count": 28, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Hello\nWorld!\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "w + \". \" + s", | |
"execution_count": 31, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'Another test. Hello, World!'" | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "\"123\" + 45", | |
"execution_count": 32, | |
"outputs": [ | |
{ | |
"ename": "TypeError", | |
"evalue": "must be str, not int", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-32-0241dda82932>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m\"123\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m45\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m: must be str, not int" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "type(10)", | |
"execution_count": 33, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "int" | |
}, | |
"execution_count": 33, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "type(\"123\")", | |
"execution_count": 34, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "str" | |
}, | |
"execution_count": 34, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "int(\"123\")", | |
"execution_count": 35, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "123" | |
}, | |
"execution_count": 35, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "int(\"hello\")", | |
"execution_count": 36, | |
"outputs": [ | |
{ | |
"ename": "ValueError", | |
"evalue": "invalid literal for int() with base 10: 'hello'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-36-a6f1987f81d0>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"hello\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: 'hello'" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "\"123\"", | |
"execution_count": 37, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'123'" | |
}, | |
"execution_count": 37, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "str(123)", | |
"execution_count": 38, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'123'" | |
}, | |
"execution_count": 38, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = input(\"Enter your name:\")\nprint(s, \", Hello\")", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter your name:\n , Hello\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "7", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "7" | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import os\nos.getcwd()", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'/Users/user/prj/oldhse-2010-11/repo/2017-18/icef-python'" | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# Задача: ввести с клавиатуры целое число, увеличить на 1 и вывести\nx = input()\nx = int(x)\nprint(x + 1)", | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "74\n75\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sqrt(100)", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name 'sqrt' is not defined", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-9-79301f9b64f1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m: name 'sqrt' is not defined" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import math", | |
"execution_count": 10, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "math.sqrt(100)", | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "10.0" | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "math.sin(math.pi)", | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "1.2246467991473532e-16" | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import math as mt", | |
"execution_count": 15, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "mt.sin(mt.pi)", | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "1.2246467991473532e-16" | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from math import sin, pi", | |
"execution_count": 19, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sin(pi)", | |
"execution_count": 20, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "1.2246467991473532e-16" | |
}, | |
"execution_count": 20, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# не делайте так:\n# from math import *", | |
"execution_count": 21, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "cos(tan(sqrt(10)))", | |
"execution_count": 22, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "0.9997860118447779" | |
}, | |
"execution_count": 22, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from math import sin as sinus", | |
"execution_count": 23, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sinus(pi)", | |
"execution_count": 24, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "1.2246467991473532e-16" | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 123", | |
"execution_count": 25, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x", | |
"execution_count": 26, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "123" | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "del x", | |
"execution_count": 27, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x", | |
"execution_count": 28, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name 'x' is not defined", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-28-6fcf9dfbd479>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m: name 'x' is not defined" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "del math", | |
"execution_count": 29, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "math.sin(0)", | |
"execution_count": 30, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name 'math' is not defined", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-30-3210f964cf2a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m: name 'math' is not defined" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from math import pi", | |
"execution_count": 33, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "pi", | |
"execution_count": 34, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "3.141592653589793" | |
}, | |
"execution_count": 34, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(f\"pi = {pi}.\")", | |
"execution_count": 37, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "pi = 3.141592653589793.\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 2\ny = 4\nprint(f\"{x} + {y} = {x + y}\")", | |
"execution_count": 39, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "2 + 4 = 6\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(\"{x} + {y} = {x + y}\")", | |
"execution_count": 40, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "{x} + {y} = {x + y}\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(f\"pi = {pi:0.4f}.\")", | |
"execution_count": 49, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "pi = 3.1416.\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list = [0, 10, 20, 30, 40]", | |
"execution_count": 50, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list", | |
"execution_count": 51, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[0, 10, 20, 30, 40]" | |
}, | |
"execution_count": 51, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[2]", | |
"execution_count": 52, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "20" | |
}, | |
"execution_count": 52, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[2] = 200", | |
"execution_count": 53, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list", | |
"execution_count": 54, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[0, 10, 200, 30, 40]" | |
}, | |
"execution_count": 54, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list.append(50)", | |
"execution_count": 58, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list", | |
"execution_count": 59, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[0, 10, 200, 30, 40, 50, 50]" | |
}, | |
"execution_count": 59, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[7] = 120", | |
"execution_count": 62, | |
"outputs": [ | |
{ | |
"ename": "IndexError", | |
"evalue": "list assignment index out of range", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-62-85fa52ec8ecd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmy_list\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m7\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m120\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mIndexError\u001b[0m: list assignment index out of range" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[-3]", | |
"execution_count": 64, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "40" | |
}, | |
"execution_count": 64, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list", | |
"execution_count": 65, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[0, 10, 200, 30, 40, 50, 50]" | |
}, | |
"execution_count": 65, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[-1]", | |
"execution_count": 66, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "50" | |
}, | |
"execution_count": 66, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "len(my_list)", | |
"execution_count": 67, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "7" | |
}, | |
"execution_count": 67, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[len(my_list)-1]", | |
"execution_count": 68, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "50" | |
}, | |
"execution_count": 68, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list", | |
"execution_count": 71, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[0, 10, 200, 30, 40, 50, 50]" | |
}, | |
"execution_count": 71, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[1:3]", | |
"execution_count": 79, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[10, 200]" | |
}, | |
"execution_count": 79, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[1:3 + 2]", | |
"execution_count": 78, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[10, 200, 30, 40]" | |
}, | |
"execution_count": 78, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[3:]", | |
"execution_count": 74, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[30, 40, 50, 50]" | |
}, | |
"execution_count": 74, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list[:3] + my_list[3:]", | |
"execution_count": 75, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[0, 10, 200, 30, 40, 50, 50]" | |
}, | |
"execution_count": 75, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "[5, 7, 9] + [3, 4, 9]", | |
"execution_count": 76, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[5, 7, 9, 3, 4, 9]" | |
}, | |
"execution_count": 76, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# concatenation", | |
"execution_count": 80, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# Slack Link: http://bit.ly/2BXZr5i\n# [email protected]\n# http://python.math-hse.info", | |
"execution_count": 81, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "type([1, 2])", | |
"execution_count": 82, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "list" | |
}, | |
"execution_count": 82, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "list(\"Hello\")", | |
"execution_count": 83, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "['H', 'e', 'l', 'l', 'o']" | |
}, | |
"execution_count": 83, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list = [1, 2]", | |
"execution_count": 84, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list.append(100)", | |
"execution_count": 85, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list", | |
"execution_count": 86, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[1, 2, 100]" | |
}, | |
"execution_count": 86, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = \"Hello\"", | |
"execution_count": 87, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s[0]", | |
"execution_count": 88, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'H'" | |
}, | |
"execution_count": 88, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s[1:3]", | |
"execution_count": 89, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'el'" | |
}, | |
"execution_count": 89, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = s.replace(\"el\", \"EELL\")", | |
"execution_count": 92, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s", | |
"execution_count": 93, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'HEELLlo'" | |
}, | |
"execution_count": 93, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = input()\ns.replace(\"a\", \"b\")\nprint(s)", | |
"execution_count": 94, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "aaawwweee\naaawwweee\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = input()\ns = s.replace(\"a\", \"b\")\nprint(s)", | |
"execution_count": 97, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "hkhaassf\nhkhbbssf\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = \"Hello, world! \\n This is a test\"", | |
"execution_count": 107, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "words = s.split()", | |
"execution_count": 108, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "words", | |
"execution_count": 109, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "['Hello,', 'world!', 'This', 'is', 'a', 'test']" | |
}, | |
"execution_count": 109, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s.split(\",\")", | |
"execution_count": 110, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "['Hello', ' world! \\n This is a test']" | |
}, | |
"execution_count": 110, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(s)", | |
"execution_count": 111, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Hello, world! \n This is a test\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "words = [\"a\", \"bb\", \"ccdd\"]\nsentence = \"---\".join(words)", | |
"execution_count": 119, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(sentence)", | |
"execution_count": 120, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "a---bb---ccdd\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "words", | |
"execution_count": 121, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "['a', 'bb', 'ccdd']" | |
}, | |
"execution_count": 121, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "for element in words: \n print(element)\n print(\"Next one\")\nprint(\"That's all\")", | |
"execution_count": 122, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "a\nNext one\nbb\nNext one\nccdd\nNext one\nThat's all\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "element", | |
"execution_count": 123, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'ccdd'" | |
}, | |
"execution_count": 123, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "for i in range(4):\n print(i)", | |
"execution_count": 124, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "0\n1\n2\n3\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "for i in range(1, 4):\n print(i)", | |
"execution_count": 125, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "1\n2\n3\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "for i in range(1, 9, 3):\n print(i)", | |
"execution_count": 128, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "1\n4\n7\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "words", | |
"execution_count": 129, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "['a', 'bb', 'ccdd']" | |
}, | |
"execution_count": 129, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "for i in range(len(words)):\n print(words[i])", | |
"execution_count": 130, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "a\nbb\nccdd\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "for word in words:\n print(word)", | |
"execution_count": 131, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "a\nbb\nccdd\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "numbers = [1, 5, 12, 6, 8]\n# задача: посчитать сумму этих чисел\nsumma = 0\nfor number in numbers:\n summa = summa + number\n # summa += number\nprint(summa)", | |
"execution_count": 134, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "32\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "summa = 10", | |
"execution_count": 138, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "del sum", | |
"execution_count": 140, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sum(numbers)", | |
"execution_count": 141, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "32" | |
}, | |
"execution_count": 141, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import math", | |
"execution_count": 135, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 7\nif x > 0:\n print(\"positive\")\nelse:\n print(\"not positive\")\nprint(\"Go ahead\")", | |
"execution_count": 146, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "positive\nGo ahead\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x > 0", | |
"execution_count": 147, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 147, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x < 0", | |
"execution_count": 148, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 148, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "6 == 7", | |
"execution_count": 149, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 149, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "7 == 7", | |
"execution_count": 150, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 150, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "6 = 7", | |
"execution_count": 151, | |
"outputs": [ | |
{ | |
"ename": "SyntaxError", | |
"evalue": "can't assign to literal (<ipython-input-151-adcc79807a81>, line 1)", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-151-adcc79807a81>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m 6 = 7\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m can't assign to literal\n" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "isinstance(6, str)", | |
"execution_count": 152, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 152, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "isinstance(\"hello\", str)", | |
"execution_count": 153, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 153, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "7 != 8\n# not equal", | |
"execution_count": 156, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 156, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "7 <> 9", | |
"execution_count": 155, | |
"outputs": [ | |
{ | |
"ename": "SyntaxError", | |
"evalue": "invalid syntax (<ipython-input-155-fe57a88c3312>, line 1)", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-155-fe57a88c3312>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m 7 <> 9\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = -6\nif x > 0:\n print(\"positive\")\nelif x < 0:\n print(\"negative\")\nelse:\n print(\"zero\")\nprint(\"Go ahead\")", | |
"execution_count": 158, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "negative\nGo ahead\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = -6\nif x > 0:\n print(\"positive\")\nprint(\"Go ahead\")", | |
"execution_count": 160, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Go ahead\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = -9\nif x > 0 and x % 2 == 0:\n print(\"x is positive and even\")\nelif x < 0 and x % 2 == 1:\n print(\"x is negative and odd\")", | |
"execution_count": 163, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "x is negative and odd\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True and True", | |
"execution_count": 164, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 164, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True and False", | |
"execution_count": 165, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 165, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True or False", | |
"execution_count": 166, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 166, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True or True", | |
"execution_count": 167, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 167, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "not True", | |
"execution_count": 168, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 168, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "to_be = False\nto_be or not to_be", | |
"execution_count": 170, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 170, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 1\nwhile x < 10:\n x = x * 2\n if x > 5:\n break\n print(x)\nprint(\"That's all\")", | |
"execution_count": 174, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "2\n4\nThat's all\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 0\nwhile True:\n x = x + 1\n print(x)\n if x > 10:\n break\n print(\"Next one\")", | |
"execution_count": 176, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "1\nNext one\n2\nNext one\n3\nNext one\n4\nNext one\n5\nNext one\n6\nNext one\n7\nNext one\n8\nNext one\n9\nNext one\n10\nNext one\n11\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.6.1", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "Python ICEF 2018, Lecture 1", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment