-
-
Save ischurov/8d6309c42b91b269dc2fa7de3bd0b558 to your computer and use it in GitHub Desktop.
lecture 4.ipynb
This file contains 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": "correct_password = \"123456\"\npassword = input(\"Please, enter password\")\nif password == correct_password:\n print(\"Access granted\")\nelse:\n print(\"Access denied\")\nprint(\"That's all\")", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Please, enter passwordasjflasjflasjdf\nAccess denied\nThat's all\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "correct_password = \"123456\"\npassword = input(\"Please, enter password\")\nif password != correct_password:\n print(\"Access denied\")\nelse:\n print(\"Access granted\")\nprint(\"That's all\")", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Please, enter passwordldjfaksdf\nAccess denied\nThat's all\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 1\ny = 2", | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x == y", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "3 == 3", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "3 != 3", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "3 > 2", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = \"Hello, world!\"\n\",\" in s", | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "\"wor\" in s", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = 5", | |
"execution_count": 10, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "if 0 < x < 10:\n print(\"x in (0, 10)\")", | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "x in (0, 10)\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "0 < 5 < 7 < 8", | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = int(input(\"Enter some small even number: \"))\nif x < 100 and x % 2 == 0:\n print(\"Okay\")\nelse:\n print(\"Not okay\")", | |
"execution_count": 20, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter some small even number: 100\nNot okay\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True and True", | |
"execution_count": 21, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True and False", | |
"execution_count": 22, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 22, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "False and True", | |
"execution_count": 23, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 23, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "False and False", | |
"execution_count": 24, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True or False", | |
"execution_count": 25, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 25, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "not True", | |
"execution_count": 26, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "to_be = False\nto_be or not to_be", | |
"execution_count": 28, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 28, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True ^ False", | |
"execution_count": 29, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 29, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "False ^ False", | |
"execution_count": 30, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 30, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "True ^ True", | |
"execution_count": 31, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = int(input(\"Enter some number\"))\nif x < 0:\n print(\"x is negative\")\nelif x < 100:\n print(\"x is small\")\nelif x < 100:\n print(\"x is not so small\")\nelse:\n print(\"x is large\")", | |
"execution_count": 35, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter some number87\nx is small\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = int(input(\"Enter some number\"))\nif x < 0:\n print(\"x is negative\")\nelse:\n if x < 100:\n print(\"x is small\")\n else:\n if x < 1000:\n print(\"x is not so small\")\n else:\n print(\"x is large\")", | |
"execution_count": 34, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter some number123\nx is not so small\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = int(input(\"Enter some number\"))\nif x > 0:\n if x % 2 == 0:\n print(\"x is positive and even\")\n else:\n print(\"x is positive and odd\")\nelse:\n if x % 2 == 0:\n print(\"x is negative and even\")\n else:\n print(\"x is positive and odd\")", | |
"execution_count": 36, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter some number12\nx is positive and even\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = input(\"Enter something: \")\nif s == \"\":\n print(\"This is nothing, not something!\")\n", | |
"execution_count": 39, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter something: \nThis is nothing, not something!\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = input(\"Enter something: \")\nif not s:\n print(\"This is nothing, not something!\")", | |
"execution_count": 40, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter something: ajdlaskjdald\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "bool(\"Hello\")", | |
"execution_count": 41, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 41, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "bool(\"\")", | |
"execution_count": 42, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 42, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "bool(3)", | |
"execution_count": 43, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 43, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "bool(0)", | |
"execution_count": 44, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 44, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "not 0", | |
"execution_count": 45, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 45, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = int(input())\nif not x:\n print(\"It's zero\")", | |
"execution_count": 48, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "-2\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x = [2]", | |
"execution_count": 50, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "bool([])", | |
"execution_count": 51, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 51, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "bool([0])", | |
"execution_count": 52, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 52, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list = []\nif my_list:\n print(\"Do something with list\")\nelse:\n print(\"The list is empty\")", | |
"execution_count": 55, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "The list is empty\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "(0.1 + 0.1 + 0.1) == 0.3", | |
"execution_count": 69, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 69, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(0.1)", | |
"execution_count": 57, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "0.1\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print('{:06.200f}'.format(0.1))", | |
"execution_count": 75, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "0.10000000000000000555111512312578270211815834045410156250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from decimal import Decimal", | |
"execution_count": 72, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "Decimal(\"0.1\") + Decimal(\"0.1\") + Decimal(\"0.1\") == Decimal(\"0.3\")", | |
"execution_count": 73, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "True" | |
}, | |
"execution_count": 73, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "Decimal(0.1)", | |
"execution_count": 76, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "Decimal('0.1000000000000000055511151231257827021181583404541015625')" | |
}, | |
"execution_count": 76, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "type(0.1)", | |
"execution_count": 77, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "float" | |
}, | |
"execution_count": 77, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from decimal import Decimal as dec", | |
"execution_count": 78, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "dec(\"0.1\") + dec(\"0.1\")", | |
"execution_count": 79, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "Decimal('0.2')" | |
}, | |
"execution_count": 79, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "печатай = print", | |
"execution_count": 80, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "печатай(\"Привет!\")", | |
"execution_count": 81, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Привет!\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sum([1, 2, 3])", | |
"execution_count": 82, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "6" | |
}, | |
"execution_count": 82, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sum = 0\nfor x in [10, 20, 30]:\n sum = sum + x\nprint(sum)", | |
"execution_count": 83, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "60\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sum", | |
"execution_count": 85, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "60" | |
}, | |
"execution_count": 85, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sum([1, 2, 3])", | |
"execution_count": 84, | |
"outputs": [ | |
{ | |
"ename": "TypeError", | |
"evalue": "'int' object is not callable", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-84-5b30f1e835bd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m: 'int' object is not callable" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "del sum", | |
"execution_count": 86, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "sum([1, 2, 3])", | |
"execution_count": 87, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "6" | |
}, | |
"execution_count": 87, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "!True", | |
"execution_count": 88, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "!ls", | |
"execution_count": 89, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Lecture 1.ipynb Untitled.ipynb lecture 03.ipynb ps01-6.ipynb\r\nLecture 2.ipynb \u001b[1m\u001b[36massignments\u001b[m\u001b[m \u001b[35mold\u001b[m\u001b[m\r\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "if (x == 0):\n print(\"Hello\")", | |
"execution_count": 95, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = \"Hello\"\nx = \"@@@\"\nif not x in s:\n print(\"Okay\")", | |
"execution_count": 96, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Okay\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s = \"Hello\"\nx = \"@@@\"\nif x not in s:\n print(\"Okay\")", | |
"execution_count": 97, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Okay\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "x", | |
"execution_count": 99, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "'@@@'" | |
}, | |
"execution_count": 99, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "not x", | |
"execution_count": 98, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "False" | |
}, | |
"execution_count": 98, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "correct_password = \"12345\"\npassword = input(\"Enter password: \")\nwhile password != correct_password:\n print(\"Password incorrect\")\n password = input(\"Enter password: \")\nprint(\"Access granted\")", | |
"execution_count": 100, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter password: alsdfjas\nPassword incorrect\nEnter password: asdfasfas\nPassword incorrect\nEnter password: asdfasfas\nPassword incorrect\nEnter password: asfafs\nPassword incorrect\nEnter password: afsfasdfasdf\nPassword incorrect\nEnter password: asfzx\nPassword incorrect\nEnter password: zafwer\nPassword incorrect\nEnter password: 123456\nPassword incorrect\nEnter password: 123456\nPassword incorrect\nEnter password: 12345\nAccess granted\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# x = 1\n# array = [1, 2, 3]\n# while x < 10:\n# print(x)\n# array = array + array", | |
"execution_count": 103, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "correct_password = \"12345\"\nwhile True:\n password = input(\"Enter password: \")\n if password == correct_password:\n break\n print(\"Password incorrect\")\nprint(\"Access granted\")", | |
"execution_count": 104, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter password: 12345\nAccess granted\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "my_list = [1, 2, 3, 100, 4, 5, 1]\nfor x in my_list:\n print(x)\n if x > 10:\n print(\"Large number detected, stopping\")\n break\nelse:\n print(\"No large numbers\")", | |
"execution_count": 112, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "1\n2\n3\n100\nLarge number detected, stopping\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from random import randrange", | |
"execution_count": 113, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "randrange(100)", | |
"execution_count": 139, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "92" | |
}, | |
"execution_count": 139, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"scrolled": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# Написать игру\n# Компьютер загадал число от 0 до 100\n# Человек его угадывает, предлагая свои догадки\n# Компьютер говорит, его число больше или меньше\n# До тех пор, пока человек не угадает\nx = randrange(101)\nwhile True:\n guess = int(input(\"Enter your guess: \"))\n if guess > x:\n print(\"Too large\")\n elif guess < x:\n print(\"Too small\")\n else:\n print(\"Correct\")\n break", | |
"execution_count": 141, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Enter your guess: 50\nToo large\nEnter your guess: 25\nToo small\nEnter your guess: 35\nToo large\nEnter your guess: 45\nToo large\nEnter your guess: 37\nToo large\nEnter your guess: 36\nToo large\nEnter your guess: 30\nToo small\nEnter your guess: 32\nToo small\nEnter your guess: 33\nCorrect\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.7.2", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "lecture 4.ipynb", | |
"public": false | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment