From c89673937e4d99cccf457f072f9b0499c7eda921 Mon Sep 17 00:00:00 2001 From: Tomasz Dwojak Date: Sat, 16 Dec 2017 06:52:54 +0100 Subject: [PATCH] Add tasks to labs 05 --- labs05/task00.py | 11 +++++++++++ labs05/task01.py | 0 labs05/task02.py | 0 labs05/task03.py | 0 labs05/task04.py | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 labs05/task00.py create mode 100644 labs05/task01.py create mode 100644 labs05/task02.py create mode 100644 labs05/task03.py create mode 100644 labs05/task04.py diff --git a/labs05/task00.py b/labs05/task00.py new file mode 100644 index 0000000..ea96b5e --- /dev/null +++ b/labs05/task00.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- + +def suma(liczby): + pass + +def main(): + print(summa([1, 2, 3, 4])) + +if __name__ == "__main__": + main() diff --git a/labs05/task01.py b/labs05/task01.py new file mode 100644 index 0000000..e69de29 diff --git a/labs05/task02.py b/labs05/task02.py new file mode 100644 index 0000000..e69de29 diff --git a/labs05/task03.py b/labs05/task03.py new file mode 100644 index 0000000..e69de29 diff --git a/labs05/task04.py b/labs05/task04.py new file mode 100644 index 0000000..4dfc78c --- /dev/null +++ b/labs05/task04.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Implementacja narzedzia ``wc`` z linuksa (word counter). +Zwraca liczbę słów, znaków i linii. +""" + +import sys + + +def count_lines(text): + """ return number of lines. """ + return len(text.strip().split('\n')) + +def count_words(text): + """ return number of words. """ + return sum([len([1 for word in line.split(' ') if len(word)]) + for line in text.split('\n')]) + +def count_chars(text): + """ return number of words. """ + return len(text) + +def wc(text): + """ proper wc """ + lines = count_lines(text) + words = count_words(text) + chars = count_chars(text) + return lines, words, chars + + +def main(): + """ main """ + print(wc(sys.stdin.read())) + + +if __name__ == "__main__": + main()