1
0
forked from tdwojak/Python2017
# Conflicts:
    #	labs02/test_task.py
This commit is contained in:
s45157 2018-01-02 02:45:14 +01:00
parent c5e0d8dddf
commit a6c2e3af77
5 changed files with 55 additions and 5 deletions

View File

@ -2,10 +2,11 @@
# -*- coding: utf-8 -*-
def suma(liczby):
pass
assert len(liczby) > 0
return reduce(lambda a, b: a+b, liczby)
def main():
print(summa([1, 2, 3, 4]))
print(suma([1, 2, 3, 4]))
if __name__ == "__main__":
main()

View File

@ -0,0 +1,7 @@
import task00, sys
def main():
print('%f' % (task00.suma(map(lambda x: float(x), sys.argv[1:]))))
if __name__ == '__main__':
main()

View File

@ -0,0 +1,12 @@
import task00, sys
def main():
def a_to_f(a):
try:
return float(a)
except:
return 0
print('%f' % (task00.suma(map(a_to_f, sys.argv[1:]))))
if __name__ == '__main__':
main()

View File

@ -0,0 +1,15 @@
import task00, argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("numbers", nargs="+")
args = parser.parse_args()
def a_to_f(a):
try:
return float(a)
except:
return 0
print('%f' % (task00.suma(map(a_to_f, args.numbers))))
if __name__ == '__main__':
main()

View File

@ -6,7 +6,7 @@ Implementacja narzedzia ``wc`` z linuksa (word counter).
Zwraca liczbę słów, znaków i linii.
"""
import sys
import sys, argparse
def count_lines(text):
@ -19,7 +19,7 @@ def count_words(text):
for line in text.split('\n')])
def count_chars(text):
""" return number of words. """
""" return number of characters. """
return len(text)
def wc(text):
@ -32,7 +32,22 @@ def wc(text):
def main():
""" main """
print(wc(sys.stdin.read()))
parser = argparse.ArgumentParser()
parser.add_argument('-l', help="number of lines", action="store_true")
parser.add_argument('-w', help="number of words", action="store_true")
parser.add_argument('-c', help="number of characters", action="store_true")
parser.add_argument('fn', nargs='?', type=file, default=sys.stdin, help='optional filename to read from')
args = parser.parse_args()
lines, words, chars = wc(args.fn.read())
if( args.l or args.w or args.c ):
if(args.l):
print(lines)
if(args.w):
print(words)
if(args.c):
print(chars)
else:
print(lines, words, chars)
if __name__ == "__main__":