forked from tdwojak/Python2017
Merge branch 'master' of https://git.wmi.amu.edu.pl/tdwojak/Python2017
# Conflicts: # labs02/test_task.py
This commit is contained in:
parent
c5e0d8dddf
commit
a6c2e3af77
@ -2,10 +2,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
def suma(liczby):
|
def suma(liczby):
|
||||||
pass
|
assert len(liczby) > 0
|
||||||
|
return reduce(lambda a, b: a+b, liczby)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(summa([1, 2, 3, 4]))
|
print(suma([1, 2, 3, 4]))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -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()
|
@ -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()
|
@ -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()
|
@ -6,7 +6,7 @@ Implementacja narzedzia ``wc`` z linuksa (word counter).
|
|||||||
Zwraca liczbę słów, znaków i linii.
|
Zwraca liczbę słów, znaków i linii.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys, argparse
|
||||||
|
|
||||||
|
|
||||||
def count_lines(text):
|
def count_lines(text):
|
||||||
@ -19,7 +19,7 @@ def count_words(text):
|
|||||||
for line in text.split('\n')])
|
for line in text.split('\n')])
|
||||||
|
|
||||||
def count_chars(text):
|
def count_chars(text):
|
||||||
""" return number of words. """
|
""" return number of characters. """
|
||||||
return len(text)
|
return len(text)
|
||||||
|
|
||||||
def wc(text):
|
def wc(text):
|
||||||
@ -32,7 +32,22 @@ def wc(text):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" 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__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user