Inspiration

What it does

How we built it

Challenges we ran into

Accomplishments that we're proud of

What we learned

What's next for File Reader

from random import randrange

def copy_file(s:str): infile_name = input("Please enter the name of the file to copy: ") infile = open(infile_name, 'r', errors='ignore') outfile_name = input("Please enter the name of the new copy: ") outfile = open(outfile_name, 'w') a=infile.readlines() start=0 end=0 if s ==('line numbers'): for i in range(len(a)): outfile.write ("{:5d}: ".format(i) + a[i])

elif s==("Gutenberg trim"):
    counter=0
    counter1=0
    for n in a:
         counter+=1
         if "*** START" in n:
             start=counter

             break
    for g in a:
         counter1 += 1 
         if "*** END"  in g:
            end=counter1 -1

            break
    x=(a[start +1:end])
    outfile.writelines(x)

elif s==("statistics"):
    empty_lines = 0
    count = 0
    all_avg = 0
    no_empty_avg = 0
    for n in a:
        for i in n.split():
            count += len(i)
        if not n.strip():
            empty_lines += 1
            no_empty_avg = count / (len(a) - empty_lines)
            all_avg= count / len(a)
    print("{:6d}   {:s}".format(len(a), "lines in the list"))
    print("{:6d}   {:s}".format(empty_lines, "empty lines"))
    print("{:8.1f} {:s}".format(all_avg , "average characters per line"))
    print("{:8.1f} {:s}".format(no_empty_avg, "average characters per non-empty line"))
    print (len(a))
else:
    print("cya nerd")

(copy_file('statistics'))

Built With

Share this project:
×

Updates