0

no idea why my program is not reading the text file correctly am I doing something wrong,
here is what i have so far

import string

count = 0

infile = open("text.txt", "r")

uppercasecount, lowercasecount, digitcount = (0, 0, 0)

def main():

for character in infile.readlines():

    if character.isupper() == True:

        uppercasecount += 1

    if character.islower() == True:
        lowercasecount += 1

    if character.isdigit() == True:

        digitcount += 1

    print(uppercasecount, lowercasecount, digitcount)

print("Total count is %d Upper case, %d Lower case and %d Digit(s)" %(uppercasecount, lowercasecount, digitcount))

main()

2
Contributors
1
Reply
12
Views
3 Years
Discussion Span
Last Post by woooee
0

no idea why my program is not reading the text file correctly

I have no idea what that means.

Print the entire string you are checking and it will show the problem with the upper/lower/digit statements. The upper and lower may work but the digit will not because the input can not be converted to an integer.

infile = open("text.txt", "r")
for character in infile.readlines():
    print repr(character)

    if character.isupper() == True:
         print "Upper"

    elif character.islower() == True:
       print "Lower"

    elif character.isdigit() == True:
       print "Digit"

    else:
        print "None of the above"

Edited by woooee

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.