programmieren_wise_24_25/Material/2.vorlesung.ipynb

1616 lines
39 KiB
Plaintext
Raw Normal View History

2024-10-28 14:49:16 +01:00
{
"cells": [
{
"cell_type": "markdown",
"id": "53ef5460-e38f-4d51-92e3-7d680f23d710",
"metadata": {},
"source": [
"# Einführung in die Programmierung für Nicht Informatiker*innen"
]
},
{
"cell_type": "markdown",
"id": "391a0811-2a99-4cde-8b88-bd7e0c1d6cb8",
"metadata": {},
"source": [
"Survey: https://survey.cyperpunk.de/form/GVkRjB"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "48342195-b5a8-4298-9f83-2908c8a52821",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hallo Python\n",
"Freitag 15h\n"
]
}
],
"source": [
"# Beispiel Print\n",
"print(\"Hallo\", \"Python\", end='\\n') # Zeigen wie end Funktioniert\n",
"print(\"Freitag 15h\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d08902d2-e454-4f81-bd63-30ef9a33deb2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Hallo Python'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"Hallo Python\""
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "63ac2349-5a3d-49f5-b379-ec92ff502694",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"432423654645"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"432423654645 "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "aa39464e-eaa1-4c8c-bd29-2ca20bc35336",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl1 = 42\n",
"zahl1"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "45281ff8-2c07-4774-9f96-e95a5b8f31ae",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"42\n"
]
}
],
"source": [
"print(zahl1)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "c9e3bf85-5b75-4efc-bbcc-9c5de28be421",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"420"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl2 = 420\n",
"zahl2"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "599a7dec-0e03-43a2-92df-a60777a33f03",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"462"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl1 + zahl2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "db143bf7-4d07-4a2b-b30a-b2f9054efeb6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-378"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl1 - zahl2"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "3b96f637-a5a2-4188-9632-a99faf881f76",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"378"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl2 - zahl1"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "7dc56688-4dd5-441d-b9f1-2c17028338e6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17640"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl2 * zahl1"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "4cb21e7e-f77d-4c5d-afb4-4aa0e7e974e5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.0"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl2 / zahl1"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "0e6a2cae-c360-454c-a622-37e6fed45879",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42.42"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"float1 = 42.42\n",
"float1"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "d360fc12-dfff-498e-95b8-664648fb8442",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl2 // zahl1"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "1813dd22-f4f0-499b-92aa-c5f5f95b8a6c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"42 % 2"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "87f97c26-4fa2-4192-ae5b-21a6adcb8aa4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(21, 0)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divmod(42, 2)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "5a8948ca-8662-43f1-9a1e-cb9bec803380",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"21.0"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"42 / 2"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "f17cc46a-906e-4fe9-9c0a-5cb81e09bcc5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"42 % 2"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "a6d36974-b750-41e8-a0b3-a40fdba9f02c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.30000000000000004"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.2"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "99e978bc-b40e-432a-81a0-801391760fb3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.2 == 0.3"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "fc761a8c-8988-4a20-81a1-28e33f11f138",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "668ad1b3-741e-46fb-a3af-375861ecbd13",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "0b23648c-1a8a-44e9-9941-a5e0e8b80ffb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True + True"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "1b91f589-8469-49cf-90ba-af14d638d8eb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1]"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l = [\"Hallo Python\", 42, 10.10]\n",
"l"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "678973b3-81ad-48e2-8ab2-c1784440a91c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1, 'Text']"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l.append(\"Text\")\n",
"l"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "0c68eb51-c5f1-4650-9032-31f77a72006f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1, 'Text']"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "e41e1c08-b570-4423-a220-c428512ab686",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.1"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g = l[2]\n",
"g"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "6a4dc400-c788-4105-a57d-c42a64bf8928",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Hallo Python'"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l[0]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "174211ad-dda8-4d43-87a1-eee4d582c47c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l[-3]"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "8ed1b344-94d0-49d6-8662-ea81d33f9d8f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Hallo Python', 42, 10.1]"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l.remove('Text')\n",
"l"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "a10e3b76-8b0c-4979-880c-cb5a86c1c42a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Tex\"t'"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"str1 = 'Tex\"t'\n",
"str1"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "783b1c13-fe63-452c-8f0e-8dab0c1173ee",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"Text'2\""
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"str2 = \"Text'2\"\n",
"str2"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "91a8fb1e-c9ba-4e37-81d4-fae62e30fc8c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'\\nHallo dies ist ein \\necht langer \\nnicht formattierter \\ntext!!!! \\' \"\\n\\n'"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"str3 = '''\n",
"Hallo dies ist ein \n",
"echt langer \n",
"nicht formattierter \n",
"text!!!! ' \"\n",
"\n",
"'''\n",
"str3"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "7fa2bc58-3cf0-4ecb-ba6e-ab0af08c2806",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Hallo dies ist ein \n",
"echt langer \n",
"nicht formattierter \n",
"text!!!! ' \"\n",
"\n",
"\n"
]
}
],
"source": [
"print(str3)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "430c663e-6320-45bb-85ac-3781394a4a37",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'x'"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"str1[2]"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "e2f20468-3ea7-411e-9c72-e29d5a344fa2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Tex\"t ist ein text'"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f\"{str1} ist ein text\""
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "58dc5f40-26df-45e8-9c36-319dce3a11cd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Tex\"t ist ein text'"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"{} ist ein text\".format(str1)"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "cf0bd9a6-db63-4795-847f-b6dbd0cd4d1e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(42, 10.1)"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tuple1 = (42, 10.10)\n",
"tuple1 "
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "6a6c1c1e-ea17-4609-82c8-2fa02b05b208",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tuple1[0]"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "a46ec0e4-0cb3-419b-ac9e-9f2a669812b0",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'tuple' object has no attribute 'append'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[71], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtuple1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m(\u001b[38;5;241m1\u001b[39m)\n",
"\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
"tuple1.append(1)"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "eb6815fd-755f-49e0-a9c3-71e28b1096c3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Name': 'Phil', 'Key': 42}"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict1 = {\"Name\": \"Phil\", \"Key\": 42}\n",
"dict1"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "3a00b7f8-910b-4261-9b49-cee2fefab2ec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict1[\"Key\"]"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "9128089a-d000-4cb3-87e3-524a53a93b84",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Name': 'Phil', 'Key': 42, 'Key2': 10}"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict1[\"Key2\"] = 10\n",
"dict1"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "07a6f887-1831-42db-a81f-69ec41b6489b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{1, 2, 3, 4}"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set1 = {1, 1, 2, 2, 3, 3, 4}\n",
"set1"
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "23dc654e-7434-4e41-8286-c9fa86aa2fae",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"42 % 2 == 0"
]
},
{
"cell_type": "code",
"execution_count": 82,
"id": "50757a7f-d3a2-43ba-9c59-f2b122661717",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ist Gerade\n"
]
}
],
"source": [
"zahl = 32\n",
"if zahl % 2 == 1:\n",
" print(\"Ist Ungerade\")\n",
"else:\n",
" print(\"Ist Gerade\")"
]
},
{
"cell_type": "code",
"execution_count": 83,
"id": "645f5df9-8ade-4cf3-aa7f-6bf642d53674",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ist Gerade\n"
]
}
],
"source": [
"zahl = 32\n",
"if not zahl % 2 == 1:\n",
" print(\"Ist Gerade\")\n",
"else:\n",
" print(\"Ist Ungerade\")"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "40d8928e-365b-4c73-a852-b13b507d7b2f",
"metadata": {},
"outputs": [],
"source": [
"if 42 % 2 == 0 and 36 % 2 == 1:\n",
" print(\"Sind beide Gerade\")"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "082f72fe-8ced-4acd-bd51-0b7bec7195a7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 87,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True and False"
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "0f911f39-056d-42bb-abfb-521fb926a1b1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Eine Zahl ist Gerade\n"
]
}
],
"source": [
"if 42 % 2 == 0 or 36 % 2 == 1:\n",
" print(\"Eine Zahl ist Gerade\")"
]
},
{
"cell_type": "code",
"execution_count": 90,
"id": "e8b94c36-e921-455a-80ae-a9f6e38a6d57",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or False"
]
},
{
"cell_type": "code",
"execution_count": 91,
"id": "e828d799-89af-4991-bdc7-39d70dd30614",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False or False"
]
},
{
"cell_type": "code",
"execution_count": 92,
"id": "db94bbb7-c422-4566-beea-d5d606825563",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or True"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "1a7093bc-a4ce-4fbd-97c0-f93570a185c7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Zahl ist durch 5 glatt teilbar\n"
]
}
],
"source": [
"zahl = 10\n",
"\n",
"if zahl % 3 == 0:\n",
" print(\"Zahl ist durch 3 glatt teilbar\")\n",
"elif zahl % 5 == 0:\n",
" print(\"Zahl ist durch 5 glatt teilbar\")\n",
"else:\n",
" print(\"Zahl ist nicht durch 3 oder 5 teilbar\")"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "eaa7e654-59b0-4ce4-80bf-f3ec83382663",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 100,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zahl = 90.0\n",
"isinstance(zahl, float)"
]
},
{
"cell_type": "code",
"execution_count": 103,
"id": "e031a4f3-b42b-4a18-872c-1241a920b842",
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" ''' Berechnet das quadrat einer Zahl'''\n",
" rückgabewert = x*x # ist der rückgabewert\n",
" return rückgabewert"
]
},
{
"cell_type": "code",
"execution_count": 104,
"id": "0f92364f-c666-485b-be38-d293cc167f17",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"49"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(7)"
]
},
{
"cell_type": "code",
"execution_count": 110,
"id": "17722b1d-0491-451f-b130-01b89ee960cf",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (2373864270.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[110], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m i = # Condition\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"i = 0 # Condition\n",
"while i < 10: # Prüfung\n",
" print(i, \"Hallo Python\")\n",
" i = i + 1 # Anpassung"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "78d52a74-2213-4560-bbde-5a83bbe845e5",
"metadata": {},
"outputs": [
{
"ename": "AssertionError",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;241m42\u001b[39m, \u001b[38;5;28mfloat\u001b[39m)\n",
"\u001b[0;31mAssertionError\u001b[0m: "
]
}
],
"source": [
"assert isinstance(42, float)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "34aab3b4-c583-4027-b75d-0d0a6a948d40",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"99 bottles of beer on the wall, 99 bottles of beer.\n",
"Take one down and pass it around, 98 bottles of beer on the wall.\n",
"\n",
"98 bottles of beer on the wall, 98 bottles of beer.\n",
"Take one down and pass it around, 97 bottles of beer on the wall.\n",
"\n",
"97 bottles of beer on the wall, 97 bottles of beer.\n",
"Take one down and pass it around, 96 bottles of beer on the wall.\n",
"\n",
"96 bottles of beer on the wall, 96 bottles of beer.\n",
"Take one down and pass it around, 95 bottles of beer on the wall.\n",
"\n",
"95 bottles of beer on the wall, 95 bottles of beer.\n",
"Take one down and pass it around, 94 bottles of beer on the wall.\n",
"\n",
"94 bottles of beer on the wall, 94 bottles of beer.\n",
"Take one down and pass it around, 93 bottles of beer on the wall.\n",
"\n",
"93 bottles of beer on the wall, 93 bottles of beer.\n",
"Take one down and pass it around, 92 bottles of beer on the wall.\n",
"\n",
"92 bottles of beer on the wall, 92 bottles of beer.\n",
"Take one down and pass it around, 91 bottles of beer on the wall.\n",
"\n",
"91 bottles of beer on the wall, 91 bottles of beer.\n",
"Take one down and pass it around, 90 bottles of beer on the wall.\n",
"\n",
"90 bottles of beer on the wall, 90 bottles of beer.\n",
"Take one down and pass it around, 89 bottles of beer on the wall.\n",
"\n",
"89 bottles of beer on the wall, 89 bottles of beer.\n",
"Take one down and pass it around, 88 bottles of beer on the wall.\n",
"\n",
"88 bottles of beer on the wall, 88 bottles of beer.\n",
"Take one down and pass it around, 87 bottles of beer on the wall.\n",
"\n",
"87 bottles of beer on the wall, 87 bottles of beer.\n",
"Take one down and pass it around, 86 bottles of beer on the wall.\n",
"\n",
"86 bottles of beer on the wall, 86 bottles of beer.\n",
"Take one down and pass it around, 85 bottles of beer on the wall.\n",
"\n",
"85 bottles of beer on the wall, 85 bottles of beer.\n",
"Take one down and pass it around, 84 bottles of beer on the wall.\n",
"\n",
"84 bottles of beer on the wall, 84 bottles of beer.\n",
"Take one down and pass it around, 83 bottles of beer on the wall.\n",
"\n",
"83 bottles of beer on the wall, 83 bottles of beer.\n",
"Take one down and pass it around, 82 bottles of beer on the wall.\n",
"\n",
"82 bottles of beer on the wall, 82 bottles of beer.\n",
"Take one down and pass it around, 81 bottles of beer on the wall.\n",
"\n",
"81 bottles of beer on the wall, 81 bottles of beer.\n",
"Take one down and pass it around, 80 bottles of beer on the wall.\n",
"\n",
"80 bottles of beer on the wall, 80 bottles of beer.\n",
"Take one down and pass it around, 79 bottles of beer on the wall.\n",
"\n",
"79 bottles of beer on the wall, 79 bottles of beer.\n",
"Take one down and pass it around, 78 bottles of beer on the wall.\n",
"\n",
"78 bottles of beer on the wall, 78 bottles of beer.\n",
"Take one down and pass it around, 77 bottles of beer on the wall.\n",
"\n",
"77 bottles of beer on the wall, 77 bottles of beer.\n",
"Take one down and pass it around, 76 bottles of beer on the wall.\n",
"\n",
"76 bottles of beer on the wall, 76 bottles of beer.\n",
"Take one down and pass it around, 75 bottles of beer on the wall.\n",
"\n",
"75 bottles of beer on the wall, 75 bottles of beer.\n",
"Take one down and pass it around, 74 bottles of beer on the wall.\n",
"\n",
"74 bottles of beer on the wall, 74 bottles of beer.\n",
"Take one down and pass it around, 73 bottles of beer on the wall.\n",
"\n",
"73 bottles of beer on the wall, 73 bottles of beer.\n",
"Take one down and pass it around, 72 bottles of beer on the wall.\n",
"\n",
"72 bottles of beer on the wall, 72 bottles of beer.\n",
"Take one down and pass it around, 71 bottles of beer on the wall.\n",
"\n",
"71 bottles of beer on the wall, 71 bottles of beer.\n",
"Take one down and pass it around, 70 bottles of beer on the wall.\n",
"\n",
"70 bottles of beer on the wall, 70 bottles of beer.\n",
"Take one down and pass it around, 69 bottles of beer on the wall.\n",
"\n",
"69 bottles of beer on the wall, 69 bottles of beer.\n",
"Take one down and pass it around, 68 bottles of beer on the wall.\n",
"\n",
"68 bottles of beer on the wall, 68 bottles of beer.\n",
"Take one down and pass it around, 67 bottles of beer on the wall.\n",
"\n",
"67 bottles of beer on the wall, 67 bottles of beer.\n",
"Take one down and pass it around, 66 bottles of beer on the wall.\n",
"\n",
"66 bottles of beer on the wall, 66 bottles of beer.\n",
"Take one down and pass it around, 65 bottles of beer on the wall.\n",
"\n",
"65 bottles of beer on the wall, 65 bottles of beer.\n",
"Take one down and pass it around, 64 bottles of beer on the wall.\n",
"\n",
"64 bottles of beer on the wall, 64 bottles of beer.\n",
"Take one down and pass it around, 63 bottles of beer on the wall.\n",
"\n",
"63 bottles of beer on the wall, 63 bottles of beer.\n",
"Take one down and pass it around, 62 bottles of beer on the wall.\n",
"\n",
"62 bottles of beer on the wall, 62 bottles of beer.\n",
"Take one down and pass it around, 61 bottles of beer on the wall.\n",
"\n",
"61 bottles of beer on the wall, 61 bottles of beer.\n",
"Take one down and pass it around, 60 bottles of beer on the wall.\n",
"\n",
"60 bottles of beer on the wall, 60 bottles of beer.\n",
"Take one down and pass it around, 59 bottles of beer on the wall.\n",
"\n",
"59 bottles of beer on the wall, 59 bottles of beer.\n",
"Take one down and pass it around, 58 bottles of beer on the wall.\n",
"\n",
"58 bottles of beer on the wall, 58 bottles of beer.\n",
"Take one down and pass it around, 57 bottles of beer on the wall.\n",
"\n",
"57 bottles of beer on the wall, 57 bottles of beer.\n",
"Take one down and pass it around, 56 bottles of beer on the wall.\n",
"\n",
"56 bottles of beer on the wall, 56 bottles of beer.\n",
"Take one down and pass it around, 55 bottles of beer on the wall.\n",
"\n",
"55 bottles of beer on the wall, 55 bottles of beer.\n",
"Take one down and pass it around, 54 bottles of beer on the wall.\n",
"\n",
"54 bottles of beer on the wall, 54 bottles of beer.\n",
"Take one down and pass it around, 53 bottles of beer on the wall.\n",
"\n",
"53 bottles of beer on the wall, 53 bottles of beer.\n",
"Take one down and pass it around, 52 bottles of beer on the wall.\n",
"\n",
"52 bottles of beer on the wall, 52 bottles of beer.\n",
"Take one down and pass it around, 51 bottles of beer on the wall.\n",
"\n",
"51 bottles of beer on the wall, 51 bottles of beer.\n",
"Take one down and pass it around, 50 bottles of beer on the wall.\n",
"\n",
"50 bottles of beer on the wall, 50 bottles of beer.\n",
"Take one down and pass it around, 49 bottles of beer on the wall.\n",
"\n",
"49 bottles of beer on the wall, 49 bottles of beer.\n",
"Take one down and pass it around, 48 bottles of beer on the wall.\n",
"\n",
"48 bottles of beer on the wall, 48 bottles of beer.\n",
"Take one down and pass it around, 47 bottles of beer on the wall.\n",
"\n",
"47 bottles of beer on the wall, 47 bottles of beer.\n",
"Take one down and pass it around, 46 bottles of beer on the wall.\n",
"\n",
"46 bottles of beer on the wall, 46 bottles of beer.\n",
"Take one down and pass it around, 45 bottles of beer on the wall.\n",
"\n",
"45 bottles of beer on the wall, 45 bottles of beer.\n",
"Take one down and pass it around, 44 bottles of beer on the wall.\n",
"\n",
"44 bottles of beer on the wall, 44 bottles of beer.\n",
"Take one down and pass it around, 43 bottles of beer on the wall.\n",
"\n",
"43 bottles of beer on the wall, 43 bottles of beer.\n",
"Take one down and pass it around, 42 bottles of beer on the wall.\n",
"\n",
"42 bottles of beer on the wall, 42 bottles of beer.\n",
"Take one down and pass it around, 41 bottles of beer on the wall.\n",
"\n",
"41 bottles of beer on the wall, 41 bottles of beer.\n",
"Take one down and pass it around, 40 bottles of beer on the wall.\n",
"\n",
"40 bottles of beer on the wall, 40 bottles of beer.\n",
"Take one down and pass it around, 39 bottles of beer on the wall.\n",
"\n",
"39 bottles of beer on the wall, 39 bottles of beer.\n",
"Take one down and pass it around, 38 bottles of beer on the wall.\n",
"\n",
"38 bottles of beer on the wall, 38 bottles of beer.\n",
"Take one down and pass it around, 37 bottles of beer on the wall.\n",
"\n",
"37 bottles of beer on the wall, 37 bottles of beer.\n",
"Take one down and pass it around, 36 bottles of beer on the wall.\n",
"\n",
"36 bottles of beer on the wall, 36 bottles of beer.\n",
"Take one down and pass it around, 35 bottles of beer on the wall.\n",
"\n",
"35 bottles of beer on the wall, 35 bottles of beer.\n",
"Take one down and pass it around, 34 bottles of beer on the wall.\n",
"\n",
"34 bottles of beer on the wall, 34 bottles of beer.\n",
"Take one down and pass it around, 33 bottles of beer on the wall.\n",
"\n",
"33 bottles of beer on the wall, 33 bottles of beer.\n",
"Take one down and pass it around, 32 bottles of beer on the wall.\n",
"\n",
"32 bottles of beer on the wall, 32 bottles of beer.\n",
"Take one down and pass it around, 31 bottles of beer on the wall.\n",
"\n",
"31 bottles of beer on the wall, 31 bottles of beer.\n",
"Take one down and pass it around, 30 bottles of beer on the wall.\n",
"\n",
"30 bottles of beer on the wall, 30 bottles of beer.\n",
"Take one down and pass it around, 29 bottles of beer on the wall.\n",
"\n",
"29 bottles of beer on the wall, 29 bottles of beer.\n",
"Take one down and pass it around, 28 bottles of beer on the wall.\n",
"\n",
"28 bottles of beer on the wall, 28 bottles of beer.\n",
"Take one down and pass it around, 27 bottles of beer on the wall.\n",
"\n",
"27 bottles of beer on the wall, 27 bottles of beer.\n",
"Take one down and pass it around, 26 bottles of beer on the wall.\n",
"\n",
"26 bottles of beer on the wall, 26 bottles of beer.\n",
"Take one down and pass it around, 25 bottles of beer on the wall.\n",
"\n",
"25 bottles of beer on the wall, 25 bottles of beer.\n",
"Take one down and pass it around, 24 bottles of beer on the wall.\n",
"\n",
"24 bottles of beer on the wall, 24 bottles of beer.\n",
"Take one down and pass it around, 23 bottles of beer on the wall.\n",
"\n",
"23 bottles of beer on the wall, 23 bottles of beer.\n",
"Take one down and pass it around, 22 bottles of beer on the wall.\n",
"\n",
"22 bottles of beer on the wall, 22 bottles of beer.\n",
"Take one down and pass it around, 21 bottles of beer on the wall.\n",
"\n",
"21 bottles of beer on the wall, 21 bottles of beer.\n",
"Take one down and pass it around, 20 bottles of beer on the wall.\n",
"\n",
"20 bottles of beer on the wall, 20 bottles of beer.\n",
"Take one down and pass it around, 19 bottles of beer on the wall.\n",
"\n",
"19 bottles of beer on the wall, 19 bottles of beer.\n",
"Take one down and pass it around, 18 bottles of beer on the wall.\n",
"\n",
"18 bottles of beer on the wall, 18 bottles of beer.\n",
"Take one down and pass it around, 17 bottles of beer on the wall.\n",
"\n",
"17 bottles of beer on the wall, 17 bottles of beer.\n",
"Take one down and pass it around, 16 bottles of beer on the wall.\n",
"\n",
"16 bottles of beer on the wall, 16 bottles of beer.\n",
"Take one down and pass it around, 15 bottles of beer on the wall.\n",
"\n",
"15 bottles of beer on the wall, 15 bottles of beer.\n",
"Take one down and pass it around, 14 bottles of beer on the wall.\n",
"\n",
"14 bottles of beer on the wall, 14 bottles of beer.\n",
"Take one down and pass it around, 13 bottles of beer on the wall.\n",
"\n",
"13 bottles of beer on the wall, 13 bottles of beer.\n",
"Take one down and pass it around, 12 bottles of beer on the wall.\n",
"\n",
"12 bottles of beer on the wall, 12 bottles of beer.\n",
"Take one down and pass it around, 11 bottles of beer on the wall.\n",
"\n",
"11 bottles of beer on the wall, 11 bottles of beer.\n",
"Take one down and pass it around, 10 bottles of beer on the wall.\n",
"\n",
"10 bottles of beer on the wall, 10 bottles of beer.\n",
"Take one down and pass it around, 9 bottles of beer on the wall.\n",
"\n",
"9 bottles of beer on the wall, 9 bottles of beer.\n",
"Take one down and pass it around, 8 bottles of beer on the wall.\n",
"\n",
"8 bottles of beer on the wall, 8 bottles of beer.\n",
"Take one down and pass it around, 7 bottles of beer on the wall.\n",
"\n",
"7 bottles of beer on the wall, 7 bottles of beer.\n",
"Take one down and pass it around, 6 bottles of beer on the wall.\n",
"\n",
"6 bottles of beer on the wall, 6 bottles of beer.\n",
"Take one down and pass it around, 5 bottles of beer on the wall.\n",
"\n",
"5 bottles of beer on the wall, 5 bottles of beer.\n",
"Take one down and pass it around, 4 bottles of beer on the wall.\n",
"\n",
"4 bottles of beer on the wall, 4 bottles of beer.\n",
"Take one down and pass it around, 3 bottles of beer on the wall.\n",
"\n",
"3 bottles of beer on the wall, 3 bottles of beer.\n",
"Take one down and pass it around, 2 bottles of beer on the wall.\n",
"\n",
"2 bottles of beer on the wall, 2 bottles of beer.\n",
"Take one down and pass it around, 1 bottle of beer on the wall.\n",
"\n",
"1 bottle of beer on the wall, 1 bottle of beer.\n",
"Take one down and pass it around, no more bottles of beer on the wall.\n",
"\n",
" No more bottles of beer on the wall, no more bottles of beer.\n",
" We've taken them down and passed them around;\n",
" now we're drunk and passed out!\n",
" \n"
]
}
],
"source": [
"beer = 99\n",
"while beer > -1:\t\n",
" print()\n",
" if beer == 0:\n",
" print('''\n",
" No more bottles of beer on the wall, no more bottles of beer.\n",
" We've taken them down and passed them around;\n",
" now we're drunk and passed out!\n",
" ''')\n",
" elif beer == 1:\n",
" print(beer, \"bottle of beer on the wall,\", beer, \"bottle of beer.\")\n",
" print(\"Take one down and pass it around, no more bottles of beer on the wall.\", end='')\n",
" else:\n",
" print(beer, \"bottles of beer on the wall,\", beer, \"bottles of beer.\")\n",
" if beer - 1 == 1:\n",
" print(f\"Take one down and pass it around, {beer - 1} bottle of beer on the wall.\") \n",
" else:\n",
" print(f\"Take one down and pass it around, {beer - 1} bottles of beer on the wall.\")\n",
" \n",
" beer -= 1\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d7fbb11-ea09-4130-9263-6a8a3bfe14a9",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}