From 57a0325708ad787702c65e8c1524d28c92449321 Mon Sep 17 00:00:00 2001 From: s45166 Date: Fri, 19 Jan 2018 22:06:33 +0100 Subject: [PATCH] Zadanie domowe labs06 --- labs05/task00.py | 5 +++-- labs05/task01.py | 10 ++++++++++ labs05/task02.py | 17 +++++++++++++++++ labs05/task03.py | 12 ++++++++++++ labs05/task04.py | 23 +++++++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/labs05/task00.py b/labs05/task00.py index ea96b5e..c06f96f 100644 --- a/labs05/task00.py +++ b/labs05/task00.py @@ -2,10 +2,11 @@ # -*- coding: utf-8 -*- def suma(liczby): - pass + liczby = [float(i) for i in liczby] + return sum(liczby) def main(): - print(summa([1, 2, 3, 4])) + print(suma([1, 2, 3, 4])) if __name__ == "__main__": main() diff --git a/labs05/task01.py b/labs05/task01.py index e69de29..c55de5c 100644 --- a/labs05/task01.py +++ b/labs05/task01.py @@ -0,0 +1,10 @@ +from task00 import suma +import sys + + +def main(): + x = sys.argv[1:] + print(suma(x)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/labs05/task02.py b/labs05/task02.py index e69de29..9ce1c77 100644 --- a/labs05/task02.py +++ b/labs05/task02.py @@ -0,0 +1,17 @@ +from task00 import suma +import sys + +def main(): + listToSum = sys.argv[1:] + + for i in listToSum: + x = listToSum.index(i) + try: + float(i) + except: + listToSum[x] = 0 + + print(suma(listToSum)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/labs05/task03.py b/labs05/task03.py index e69de29..930aaea 100644 --- a/labs05/task03.py +++ b/labs05/task03.py @@ -0,0 +1,12 @@ +from task00 import suma +import argparse + +def main(): + parse = argparse.ArgumentParser() + parse.add_argument("float", help="floating numbers", nargs = '+') + arguments = parse.parse_args() + result = arguments.float + print(suma(result)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/labs05/task04.py b/labs05/task04.py index 4dfc78c..48671de 100644 --- a/labs05/task04.py +++ b/labs05/task04.py @@ -7,6 +7,7 @@ Zwraca liczbę słów, znaków i linii. """ import sys +import argparse def count_lines(text): @@ -34,6 +35,28 @@ def main(): """ main """ print(wc(sys.stdin.read())) + parse = argparse.ArgumentParser() + parse.add_argument('--l', help = 'number of lines', action = 'store_true') + parse.add_argument('--w', help = 'number of words', action = 'store_true') + parse.add_argument('--c', help = 'number of characters', action = 'store_true') + parse.add_argument('file', help = 'filepath', type = argparse.FileType('f'), nargs = '?') + args = parse.parse_args() + + if args.file is None: + opt = sys.stdin.read() + else: + opt = args.file.read() + + if args.l: + output = count_lines(opt) + elif args.w: + output = count_words(opt) + elif args.c: + output = count_chars(opt) + else: + output = wc(opt) + + print(output) if __name__ == "__main__": main()