forked from tdwojak/Python2017
Zadanie domowe labs06
This commit is contained in:
parent
6cf371942e
commit
57a0325708
@ -2,10 +2,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
def suma(liczby):
|
def suma(liczby):
|
||||||
pass
|
liczby = [float(i) for i in liczby]
|
||||||
|
return sum(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,10 @@
|
|||||||
|
from task00 import suma
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x = sys.argv[1:]
|
||||||
|
print(suma(x))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -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()
|
@ -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()
|
@ -7,6 +7,7 @@ Zwraca liczbę słów, znaków i linii.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def count_lines(text):
|
def count_lines(text):
|
||||||
@ -34,6 +35,28 @@ def main():
|
|||||||
""" main """
|
""" main """
|
||||||
print(wc(sys.stdin.read()))
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user