{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# İleri Seviye Sayılar\n", "Bu konuda sayı veritiplerini biraz daha derinlemesine incelemeye ve sayılar üzerinde uygulanabilen yararlı fonksiyonları öğrenmeye çalışacağız. \n", "\n", "\n", "Bazen programlamada sayılarımızı 10'luk taban haricinde 2'lik(binary) ve 16'lık(hexadecimal) tabanda göstermek ve kullanmak isteyebiliriz.\n", "\n", "10'luk tabandaki sayıları 2'lik ve 16'lık tabanda göstermeye başlamadan önce şu linklerden 2'lik(binary) ve 16'lık(hexadecimal) tabanları incelemenizi tavsiye ediyorum.\n", "\n", "https://www.turkcebilgi.com/ikili_(binary)_say%C4%B1_sistemleri\n", "\n", "http://www.blogkafem.net/2014/01/sayi-sistemleri.html\n", "\n", "Şimdi isterseniz 10'luk tabandaki bir sayıyı ikilik tabana çevirmek için kullanılan ***bin()*** fonksiyonuna bakalım." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b100'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(4) # bin fonksiyonu . Sayımız 2'lik tabanda yazıldı. (1 ve 0)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b10011'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(19) # bin fonksiyonu . Sayımız 2'lik tabanda yazıldı. (1 ve 0)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b1000001001'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(521) # bin fonksiyonu . Sayımız 2'lik tabanda yazıldı. (1 ve 0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Şimdi de 10'luk tabandaki bir sayıyı 16'lık tabana çevirmek için kullanılan **hex()** fonksiyonuna bakalım." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x20'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(32) # Sayımız 16'lık tabanda yazıldı." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x36'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(54) # Sayımız 16'lık tabanda yazıldı." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x4bc'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(1212) # Sayımız 16'lık tabanda yazıldı." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fonksiyonlar" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### abs fonksiyonu\n", "\n", "Sayının mutlak değerini almamızı sağlar.\n" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(-4)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4.5" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(4.5)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(0)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(-10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### round fonksiyonu\n", "\n", "Sayıları alta veya üste yuvarlar." ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(3.7)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(3.2)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(3)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.2133" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(3.21329321321323,4) # Ondalıklı sayının 4. hanesine göre yuvarlar" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.2132" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(3.21324321321323,4) # Ondalıklı sayının 4. hanesine göre yuvarlar" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### max ve min fonksiyonu\n", "\n", "\n", "\n", "***max()*** fonksiyonu verdiğimiz değerlerin en büyüğünü döndürür.\n", "\n", "***min()*** fonksiyonu verdiğimiz değerlerin en küçüğünü döndürür." ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "max(3,4) # İstediğimiz kadar değer verebiliriz." ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "131" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "max(100,-2,3,4,1,131) # İstediğimiz kadar değer verebiliriz." ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "15.6" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "max([13.2,-4.32,1.2,15.6]) # Sayıları liste şeklinde de verebiliriz." ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "15.6" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "max((13.2,-4.32,1.2,15.6)) # Sayıları demet şeklinde de verebiliriz." ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "min(3,4)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-2" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "min(100,-2,3,4,1,131)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### sum fonksiyonu\n", "\n", "***sum() fonksiyonu*** verilen değerleri toplayarak döndürür. Değerlerin liste,demet vb. şeklinde verilmesi gerekir." ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "'int' object is not iterable", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mTypeError\u001b[0m: 'int' object is not iterable" ] } ], "source": [ "sum(3,4)" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "25" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sum([3,4,5,6,7])" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sum((3,4))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### pow fonksiyonu\n", "\n", "***pow() fonksiyonu*** üs alma işlemlerinde kullanılır. " ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "16" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pow(2,4) # 2 üzeri 4" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "81" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pow(3,4) # 3 üzeri 4" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "289" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pow(17,2) # 17 üzeri 2" ] } ], "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.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }