samedi 20 décembre 2014

Why does this if statement not work in this case? [on hold]

In this code I ask the user which way they want the text file ordered however, when run the if statement will not work and when run without the if statement it does work. Why will it not work?



way = int(input('Which way would you like the data to be sorted, Alphabetical[1], Ascending[2] Descending[3] or Average[4]'))
classno = str(input('Which class would you like to sort? Please state the entire class name no spaces please with .txt on the end'))

if way=='1':# WORKS with classno but not with if statement
f = open(classno, "r")# omit empty lines and lines containing only whitespace
lines = [line for line in f if line.strip()]
f.close()
lines.sort()# now write the output file
f = open(classno, 'w')
f.writelines(lines) # Write a sequence of strings to a file
f.close()


The other codes which i have not displayed have the same problems and all work without the if statement They all use an if statement no elif ect. if that is any use.


Aucun commentaire:

Enregistrer un commentaire