Read and Write file practice - Usernames


In [ ]:
def batchUnames():
    fname = 'c:/Python27/Methods_1/class_list.txt'
    infile = open(fname, "r")
    class_list = infile.readlines()
    infile.close()
    #print class_list


    out_filename = "c:/Python27/Methods_1/batch_unames.txt"
    outfile = open(out_filename, "w")
    for item in class_list:
        name = item.split()    
        first = name[0].lower()
        last = name[1].lower()
        f= first[0]
        l = last[:7]
        user = f+l
        entry = user+"\n"
        outfile.write(entry)

    outfile.close()        
    print "Your filename has been written to %s" %(out_filename)

batchUnames()

isOdd version 1.0


In [ ]:
def isOdd():
    
    print "This function will print a 0 if your number is even and a 1 if your number is odd."
    print "Note: this program does not handle 0's properly."
    check = input("What number would you like to check? :")
    output = check%2
    print output
isOdd()