Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 238 additions & 0 deletions Huisewerk week3-islam.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1-perfect_number.py\n",
"Perfect number: Perfect number is a positive integer that is equal to the sum of its proper divisors.\n",
"\n",
"The smallest perfect number is 6, which is the sum of 1, 2, and 3.\n",
"\n",
"Some other perfect numbers are 28(1+2+4+7+14=28), 496 and 8128.\n",
"\n",
"Write a function that finds perfect numbers between 1 and 1000. Check perfect numbers between 1 and 1000 and find the sum of the perfect numbers using reduce and filter functions."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6\n",
"24\n",
"28\n",
"496\n"
]
}
],
"source": [
"for i in range(1,1001):\n",
" count=0\n",
" for z in range(1,i):\n",
" if i%z==0:\n",
" count+=z\n",
" if count==i:\n",
" print(i)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2-alphabetical_order.py\n",
"Write a function that takes an input of different words with hyphen (-) in between them and then:\n",
"\n",
"sorts the words in alphabetical order,\n",
"adds hyphen icon (-) between them,\n",
"gives the output of the sorted words."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lutfen farkli kelimeri giriniz:AKMEK selam millet bak\n",
"akmek-bak-millet-selam\n"
]
}
],
"source": [
"c=input(\"lutfen farkli kelimeri giriniz:\")\n",
"c=c.lower()\n",
"c=c.split(\" \")\n",
"c.sort()\n",
"print(\"-\".join(c))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3-Write a function that filters all the unique(unrepeated) elements of a given list.\n",
"\n",
"Example:\n",
"\n",
"Function call: unique_list([1,2,3,3,3,3,4,5,5])\n",
"Output : [1, 2, 3, 4, 5]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5]\n"
]
}
],
"source": [
"liste=[1,2,3,3,3,3,4,5,5]\n",
"unique=[]\n",
"for i in liste:\n",
" if i not in unique:\n",
" unique.append(i)\n",
"print(unique) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4-Write a function that controls the given inputs whether they are equal to their reversed order or not.\n",
"\n",
"Example:\n",
"\n",
"Input >>> madam, tacocat, utrecht \n",
"Output >>> True, True, False"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Lutfen bir kelime girin:selam\n",
"selam = False\n"
]
}
],
"source": [
"kelime=input(\"Lutfen bir kelime girin:\")\n",
"kelime1=kelime[ : :-1]\n",
"if kelime==kelime1:\n",
" print(kelime,\"=\",True)\n",
"else:\n",
" print(kelime,\"=\",False)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"5-Write a function that outputs the transcription of an input number with two digits.\n",
"\n",
"Example:\n",
"\n",
"28---------------->Twenty Eight"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lutfen bir sayi giriniz:23\n",
"yirmi uc\n"
]
}
],
"source": [
"def reading_numbers(number):\n",
" birler=[\"bir\",\"iki\",\"uc\",\"dort\",\"bes\",\"alti\",\"yedi\",\"sekiz\",\"dokuz\"]\n",
"\n",
" onlar=[\"on\",\"yirmi\",\"otuz\",\"kirk\",\"elli\",\"altmis\",\"yetmis\",\"seksen\",\"doksan\"]\n",
" \n",
"\n",
" if int(number[1]) == 0:\n",
" print(onlar[int(number[0])-1])\n",
" else:\n",
" b=birler[int(number[1])-1]\n",
"\n",
" o=onlar[int(number[0])-1]\n",
"\n",
" return print(\"{} {}\".format(o,b))\n",
"\n",
"number=input(\"lutfen bir sayi giriniz:\")\n",
"reading_numbers(number)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}