I am new to python (2nd) day and working on a problem that asks me to Write a program that reads ASCII files (asks for file name as input), checks if it has more than two words and prints out the two first words of the file on screen.
Its a little vague but I am going to assume the file is all str, deliminiated by spaces.
ex.
text1 text2 text text text
So far I have:
name = (raw_input("Please enter the name of the file: "))
f=open(name)
with codecs.open(name, encoding='utf-8') as f:
    for line in f:
        line = line.lstrip(BOM)
words=line.split()
print words
if len(words) > 2:
    print 'There are more than two words'
    firsttow = words[:2]
    print firstrow
I am having problems writing the else statement, I want to have,
if len(words) > 2:
    print 'There are more than two words'
    firsttow = words[:2]
print firstrow
else: 
if len(words) <2:
        print 'There are under 2 words, no words will be shown'
How should this be added and is there any other ways to improve my code for this questions? I really appreciate the help
Thanks in advance
*Edit: Thanks for all the help, the last problem I had was when i run .py file, I want to be able to see the results before the cmd window closes.
Adding: raw_input("Press return to close this window...") does notwork and it closes right away. Any ideas?
Edit2* This is my current code, still trying to work on having the cmd window open after
import codecs
BOM = codecs.BOM_UTF8.decode('utf8')
name = (raw_input("Please enter the name of the file: "))
with codecs.open(name, encoding='utf-8') as f:
    words=[]            #define words here
    for line in f:
        line = line.lstrip(BOM)
        words.extend(line.split())        #append words from each line to words  
if len(words) > 2:
    print 'There are more than two words'
    firstrow = words[:2]
    print firstrow                #indentation problem here
elif len(words) <2:                    #use if
    print 'There are under 2 words, no words will be shown'
raw_input("Press return to close this window...")


forloop you will only look at the file's last line.raw_input("Press return to close this window...")?