PracticeForExam

This commit is contained in:
2024-12-05 23:20:53 +01:00
parent bcff76d934
commit a1e0e21582
5 changed files with 240 additions and 34 deletions

View File

@ -45,10 +45,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The number of different letters in the string is: 24\n",
"Ez egy lottószám: 64\n",
"Ez egy lottószám: 1\n",
"Ez egy lottószám: 6\n",
"Ez egy lottószám: 15\n",
"Ez egy lottószám: 30\n",
"[2, 1, 3, 9, 5, 10, 8, 6, 4, 7]\n"
]
}
],
"source": [
"text = \"Tis is a string with several andeven some more text inside, so we can decide how many different letters are used in it!\"\n",
"\n",
"print(f\"The number of different letters in the string is: {len(set(text))}\")\n",
"\n",
"import random\n",
"\n",
"lotto = set()\n",
"while len(lotto) < 5:\n",
" lotto.add(random.randint(1, 90))\n",
"\n",
"print('\\n'.join(['Ez egy lottószám: '+ str(i) for i in lotto]))\n",
"\n",
"\n",
"#veletlen sorrend:\n",
"numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
"random.shuffle(numbers)\n",
"print(numbers)\n"
]
},
{
"cell_type": "markdown",
@ -61,7 +93,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -75,7 +107,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,

View File

@ -66,8 +66,49 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[100, 90, 80, 70, 60, 50, 40, 30, 20, 10]\n",
"[2, 3]\n",
"{'alma': 10, 'körte': 20, 'barack': 30}\n"
]
},
{
"ename": "TypeError",
"evalue": "len() takes exactly one argument (0 given)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 20\u001b[0m\n\u001b[1;32m 16\u001b[0m mydict\u001b[38;5;241m.\u001b[39mupdate({mylist[i] : \u001b[38;5;28mint\u001b[39m(mylist[i\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m])})\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28mprint\u001b[39m(mydict)\n\u001b[0;32m---> 20\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__doc__\u001b[39m)\n",
"\u001b[0;31mTypeError\u001b[0m: len() takes exactly one argument (0 given)"
]
}
],
"source": [
"tomb = [i*10 for i in range(10, 0,-1)]\n",
"\n",
"print(tomb)\n",
"\n",
"\n",
"lista1 = [-1, 2, 0, 3]\n",
"lista2 = [i for i in lista1 if i > 0]\n",
"\n",
"print(lista2)\n",
"\n",
"todict = 'alma,10,körte,20,barack,30'\n",
"mylist = todict.split(',')\n",
"mydict = {}\n",
"\n",
"for i in range(0, len(mylist)-1, 2):\n",
" mydict.update({mylist[i] : int(mylist[i+1])})\n",
"\n",
"print(mydict)\n",
"\n"
]
},
{
"cell_type": "markdown",
@ -83,7 +124,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -97,7 +138,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,

View File

@ -25,10 +25,57 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"True\n",
"4\n"
]
},
{
"data": {
"text/plain": [
"'Returns the value of a binary number sent as a string!'"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def kulonbozo(str1, str2):\n",
" if sorted(str1) == sorted(str2):\n",
" return False\n",
" else:\n",
" return True\n",
"\n",
"\n",
"print(kulonbozo(\"Alma\", \"amlA\"))\n",
"print(kulonbozo(\"Almas\", \"amlA\"))\n",
"\n",
"\n",
"def convert(str1):\n",
" number = 0\n",
" counter = 0\n",
" while len(str1) > 0:\n",
" if str1[len(str1)-1] == '1':\n",
" number += counter **2\n",
" counter += 1\n",
" str1 = str1[:len(str1)-1]\n",
" return number\n",
"\n",
"print(convert('101'))\n",
"\n",
"convert.__doc__ = \"Returns the value of a binary number sent as a string!\"\n",
"\n",
"convert.__doc__\n"
]
},
{
"cell_type": "markdown",
@ -48,7 +95,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -62,7 +109,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,

View File

@ -48,15 +48,15 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"42\n",
"58\n"
"53\n",
"47\n"
]
}
],
@ -78,10 +78,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"54\n",
"46\n"
]
}
],
"source": [
"x = [random.choice([\"fej\", \"írás\"]) for i in range(100)]\n",
"\n",
"print(x.count(\"fej\"))\n",
"print(x.count(\"írás\"))"
]
},
{
"cell_type": "markdown",
@ -132,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
@ -175,10 +189,46 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['H', 'H', 'H', 'T', 'T', 'T', 'H', 'T', 'H', 'H']\n",
"3\n",
"2\n"
]
}
],
"source": [
"# ... a leghosszabb sorozat hossza (nem külön-külön számolva)\n",
"\n",
"import random\n",
"n = 10\n",
"sorsolas = [random.choice('HT') for i in range(n)]\n",
"\n",
"sorozat = 1\n",
"sorozat_max = 1\n",
"db = 0\n",
"for x in range(1, n):\n",
" if sorsolas[x] == sorsolas[x - 1]:\n",
" sorozat += 1\n",
" else:\n",
" sorozat = 1\n",
" \n",
" if sorozat > sorozat_max:\n",
" sorozat_max = sorozat\n",
" db = 0\n",
"\n",
" if sorozat == sorozat_max:\n",
" db+= 1\n",
" \n",
"print(sorsolas)\n",
"print(sorozat_max)\n",
"print(db)"
]
},
{
"cell_type": "markdown",
@ -210,10 +260,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"7924\n"
]
}
],
"source": [
"import datetime\n",
"import random\n",
"\n",
"\n",
"born = datetime.date(2003,3,27)\n",
"today = datetime.date.today()\n",
"dif = today - born\n",
"\n",
"print(dif.days)\n",
"\n",
"rnum = datetime.date(2024, random.randint(1,12), random.randint(1,27))\n",
"\n"
]
},
{
"cell_type": "markdown",
@ -227,7 +298,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -241,7 +312,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,

View File

@ -24,15 +24,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[6, 5, 3, 4, 6, 5, 8, 3, 6, 5]]\n"
]
}
],
"source": [
"lines = []\n",
"with open(\"matrix.txt\") as file:\n",
" lines.append([list(map(int,i.strip().split())) for i in file.readlines()])\n",
"\n",
"\n",
"print([list(map(sum,i)) for i in lines])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@ -46,7 +61,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,