From f04041a3fed9165f16b7ced7db9372cd0d6f7b38 Mon Sep 17 00:00:00 2001 From: s45153 Date: Sat, 2 Dec 2017 19:19:25 +0000 Subject: [PATCH] Upload files to 'la' --- la/Podstawy 2.ipynb | 479 ++++++++++++++++++++++++++++++++++++++++++++ la/README.md | 3 + la/cw_3.py | 48 +++++ la/haslo2.txt | 1 + la/haslo23.txt | 1 + 5 files changed, 532 insertions(+) create mode 100644 la/Podstawy 2.ipynb create mode 100644 la/README.md create mode 100644 la/cw_3.py create mode 100644 la/haslo2.txt create mode 100644 la/haslo23.txt diff --git a/la/Podstawy 2.ipynb b/la/Podstawy 2.ipynb new file mode 100644 index 0000000..70c44ec --- /dev/null +++ b/la/Podstawy 2.ipynb @@ -0,0 +1,479 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# Python: podstaw ciąg dalszy\n", + "\n", + "## Tomasz Dwojak\n", + "\n", + "### 2 grudnia 2017" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Co już znamy?\n", + " * podstawowe typy danych i operacje na nich\n", + " * Instrukcje sterujące: ``if``, ``for``\n", + " * pisanie funkcji\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "source": [ + "## Co na dziś?\n", + "\n", + " * ``tuple`` i ``set``,\n", + " * operacje na plikach,\n", + " * coś więcej o funkcjach\n", + " * korzystanie z bibliotek\n", + " * przegląd najważniejszych bibliotek" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "def dwojak(x): x *= 2\n", + " \n", + "l = [1, 2, 3]\n", + "s = \"123\"\n", + "\n", + "dwojak(l)\n", + "dwojak(s)\n", + "\n", + "print(l)\n", + "print(s)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Mutable i Immutable\n", + "\n", + "### Mutable\n", + " * listy,\n", + " * słowniki,\n", + " * sety,\n", + " * własnoręcznie zdefiniowane klasy.\n", + " \n", + "### Immutable\n", + " * liczby: inty i floaty,\n", + " * napisy,\n", + " * tuple." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Nieoczywistości" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "def dwojak1(x): x *= 2\n", + "def dwojak2(x): x = x * 2\n", + "\n", + "l = [1,2, 3]\n", + "dwojak1(l)\n", + "print(l)\n", + "\n", + "l = [1,2, 3]\n", + "dwojak2(l)\n", + "print(l)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "l = [1, 2, 3]\n", + "e = l\n", + "e.append(4)\n", + "print(l)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "e = []\n", + "f = [e for i in range(3)]\n", + "f[0].append(1)\n", + "print(f)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## To może ``tuple``?\n", + " * stały rozmiar,\n", + " * immutable,\n", + " * mogą być kluczami w słownikach" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "t = (1, \"napis\", None)\n", + "elem = t[0]\n", + "print(t)\n", + "print(len(t))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Funkcje cz. 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "def suma(*args):\n", + " return sum(args)\n", + "print(suma(1,2,3,4,5))\n", + "\n", + "def greet_me(**kwargs):\n", + " if kwargs is not None:\n", + " for key, value in kwargs.items():\n", + " print(\"%s == %s\" %(key,value))\n", + "greet_me(a=1, b=(3,4))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Generatory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "def alfaRange(x, y):\n", + " for i in range(ord(x), ord(y)):\n", + " yield chr(i)\n", + "\n", + "for c in alfaRange('a', 'e'):\n", + " print(c)\n", + " ##druga wersja; w Pythonie3 f range rozni sie od 2\n", + "def alfaRange(x, y):\n", + " for i in range(ord(x), ord(y)):\n", + " print(i)\n", + " yield chr(i)\n", + "\n", + "for c in alfaRange('a', 'e'):\n", + " print(c)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Operacje na plikach" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "plik = open(\"haslo.txt\", 'r') ## r - read only\n", + "for linia in plik.readlines():\n", + " print(linia.strip())\n", + "print(plik.read())\n", + "print(\">>\")\n", + "plik.close() ## jesli nie uzyjemy tej funkcji przy duzej liczbie plikow, to skoncza sie deskryptory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "with open(\"haslo.txt\", 'r') as plik: ## wygodne do pracy z plikami\n", + " for linia in plik.readlines():\n", + " print(linia)\n", + "# print(plik.read()) ##nie trzeba zamykac plikow" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true, + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "with open(\"haslo2.txt\", 'w') as plik: ## write - zapis do pliku\n", + " for word in ('corect', 'horse', 'battery', 'staple'):\n", + " plik.write(word)\n", + " plik.write('\\n')\n", + "with open(\"haslo2.txt\", 'w+') as plik:\n", + " plik.writelines([' '.join(('corect', 'horse', 'battery', 'staple'))])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# Korzystanie z modułów" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Importowanie" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "import os ##ta biblioteka pozwala na operacje na systemie operacyjnym\n", + "print(os.name)\n", + "\n", + "from os import getenv\n", + "print('Nazwa uzytkownika: {}'.format(getenv(\"USER\")))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "from collections import *\n", + "print(Counter(\"konstantynopolitańczykowianeczka\"))\n", + "\n", + "import numpy as np\n", + "np.array([[1, 3, 4, 5]], dtype='float32')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Instalacja\n", + "\n", + " * lokalnie (per użytkownik) lub globalnie\n", + " * pyCharm lub linia komend, np. ``pip install --user flask`` lub ``python -m pip install --user flask``" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Wczytywanie z klawiatury" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "name = input(\"What's your name?\\n\")\n", + "print(\"Welcome home, {}.\".format(name))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "liczby = eval(input(\"Podaj liczby\"))\n", + "print(sum(liczby))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Co ominąłem?\n", + "\n", + " * klasy (jutro)\n", + " * podział programu na pliki (jutro)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "celltoolbar": "Slideshow", + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/la/README.md b/la/README.md new file mode 100644 index 0000000..2758558 --- /dev/null +++ b/la/README.md @@ -0,0 +1,3 @@ +Link do arkusza z obecnością: + +https://docs.google.com/spreadsheets/d/1TxJSYM-voKJ7siCgtkCS77pSF0l7I-OtzfCrQdq9RtE/edit?usp=sharing \ No newline at end of file diff --git a/la/cw_3.py b/la/cw_3.py new file mode 100644 index 0000000..bd89124 --- /dev/null +++ b/la/cw_3.py @@ -0,0 +1,48 @@ +def suma(*args): ## funkcja przejmuje wszystkie argumenty, ktore nie zostaly nazwane (arguments) + return sum(args) +print(suma(1,2,3,4,5)) + +def suma(x, *args): ### x bedzie 1, a reszta argumentow bedzie podstawiona do do args i wydzie 14 + return sum(args) +print(suma(1,2,3,4,5)) + +def greet_me(**kwargs): ##key-word arguments + if kwargs is not None: + for key, value in kwargs.items(): + print("%s == %s" %(key,value)) +greet_me(a=1, b=(3,4)) + +def greet_me(z=None,**kwargs): ##key-word arguments; przydatne dla funkcji, ktore przyjmuja bardzo duzo argumentow + if kwargs is not None: + for key, value in kwargs.items(): + print("%s == %s" %(key,value)) +greet_me(a=1, b=(3,4)) + +plik = open("haslo.txt", 'r') ## r - read only +for linia in plik.readlines(): + print(linia.strip()) +print(plik.read()) +plik.close() + +plik = open("haslo.txt", 'r') ## r - read only +for linia in plik.readlines(): + print(linia.strip()) +print(plik.read()) +print(">>") +plik.close() + +with open("haslo23.txt", 'w') as plik: ## write - zapis do pliku + for word in ('corect ', 'horse ', 'battery', 'staple'): + plik.write(word) + plik.write('\n') +with open("haslo2.txt", 'w+') as plik: + plik.writelines([' '.join(('corect', 'horse', 'battery', 'staple'))]) + +import os ##ta biblioteka pozwala na operacje na systemie operacyjnym +print(os.name) + +from os import getenv +print('Nazwa uzytkownika: {}'.format(getenv("USER"))) + +name = input("What's your name?\n") +print("Welcome home, {}.".format(name)) \ No newline at end of file diff --git a/la/haslo2.txt b/la/haslo2.txt new file mode 100644 index 0000000..0bbe445 --- /dev/null +++ b/la/haslo2.txt @@ -0,0 +1 @@ +corect horse battery staple \ No newline at end of file diff --git a/la/haslo23.txt b/la/haslo23.txt new file mode 100644 index 0000000..4a5834e --- /dev/null +++ b/la/haslo23.txt @@ -0,0 +1 @@ +corect horse batterystaple