0

Hey guys i'm new here, but i got the basics of python down and i'm having some problems with my code. All i want to do is be able to type in something and have it saved as a txt file, i have tryed numerous things and when i ran the program all it would do is go to the end of it. Heres the code:

choice = 0

print "---------------"
print "---Security---"
print "--------Log - In----"
print "--------------------------"

password = raw_input("Password: ")
password.lower() == "asdf"
print "Welcome John"
print " "

print "You can: "
print " "
print "1) Read Files"

choice = raw_input("Choose your option: ")

if choice == 1:
    myfile = open('myfile.txt', 'r').open()

Thanks

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by tondeuse34
0

Hi There,

Bunches of problems with your code but here is something to get you started..

print "You can: "
print " "
print "1) Read Files"
print "2) Write Files"

choice = int(raw_input("Choose your option: ").strip())

if choice == 1:
    myfile = open('myfile.txt', 'r').open()
    myfile.close()
elif choice == 2:
    myfile = open('myfile.txt', 'w')
    for x in range (10):
        myfile.write( "%s\n" % x)
    myfile.close()
else:
    print "%s Not an option" % choice
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.