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

@ -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,