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

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

Thanks guys for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.