1
0
forked from tdwojak/Python2017

Zadanie domowe labs06

This commit is contained in:
s45166 2018-01-19 22:06:33 +01:00
parent 6cf371942e
commit 57a0325708
5 changed files with 65 additions and 2 deletions

View File

@ -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()

View File

@ -0,0 +1,10 @@
from task00 import suma
import sys
def main():
x = sys.argv[1:]
print(suma(x))
if __name__ == "__main__":
main()

View File

@ -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()

View File

@ -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()

View File

@ -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()