Beginners help with password program!

T

tjland

This is my first version of this program, im kinda new to python and i was
wondering if someone could help me with this. Their are some errors that i
just cant find, and i want some advice on how to do some of these things
easier. Thanx for the help!
----------------------------------------------------------------------------
from time import sleep

def Sendfile(password, username):
outfile = file(username, "w")
outfile.write(password)
outfile.close()
print "Your are now registered"

def Getfile(username):
infile = file(username, "r")
content = infile.readline(1)
global content
infile.close()


login = input("Are u registered? ")
if login == no:
new_username = input("What do you want for a username, please letters
only: ")
new_password = input("What do you wish for a password: ")
Sendfile(new_password, new_username)
else:
print "Please Login, Enter username, then wait for prompt!"
username = input("Username: ")
sleep(5)
password = input("Password: ")

Getfile(username)
if password != content:
print """Im sorry but you are not a registered user,
If you would like to become a user contact the server admin for
user privelges"""
else:
print "Welcome"
----------------------------------------------------------------------------

When you see the net take the shot
When you miss your shot shoot again
When you make your shot you win!

Just remember
Offense sells tickets
But defense wins championships!
 
B

Ben Finney

Their are some errors that i
just cant find,

Please show the errors you get, so we know what you're talking about.
and i want some advice on how to do some of these things easier.

Here's advice on finding errors:

When you encounter an error you don't understand, *don't* try to deal
with the whole program. Take a copy, or make a new program (whichever
seems simpler at the time) and get to the smallest possible program you
can make that still exhibits the error.

This will result in several things:

you may end up solving the error; otherwise:

you may understand the error much better

you will know exactly which lines of code are related to the error

you will have something suitable to post to this newsgroup.

Please don't just post the whole program and say "find my error".
That's *your* task.
 
K

Keith Jones

For starters, I suggest you install pychecker and use it on any programs
you create.

Second, every error in python should give you some information as to what
line it occurred on. For example:

: a = b
:Traceback (most recent call last):
: File "<pyshell#29>", line 1, in ?
: a = b
:NameError: name 'b' is not defined

Here it says line 1, because this occurred in Idle. Start by going to that
line... 90% of the time, your error will be right there.

As for your file... well the line if "login == no:" looks wrong, unless
you have a variable named 'no'.. you probably want the string 'no' there.
As was mentioned, you probably won't get much help if you ask people to
debug for you. Debugging is a major part of programming, and you can't
avoid it. So get used to it and get good at it. :D (and learn to test your
code thoroughly). Finally, I recommend you use raw_input(...), rather
than input(...), and then convert the return value from a string to
whatever you need it to be.
 
T

tjland

For starters, I suggest you install pychecker and use it on any programs
you create.

Second, every error in python should give you some information as to what
line it occurred on. For example:

: a = b
:Traceback (most recent call last):
: File "<pyshell#29>", line 1, in ?
: a = b
:NameError: name 'b' is not defined

Here it says line 1, because this occurred in Idle. Start by going to that
line... 90% of the time, your error will be right there.

As for your file... well the line if "login == no:" looks wrong, unless
you have a variable named 'no'.. you probably want the string 'no' there.
As was mentioned, you probably won't get much help if you ask people to
debug for you. Debugging is a major part of programming, and you can't
avoid it. So get used to it and get good at it. :D (and learn to test your
code thoroughly). Finally, I recommend you use raw_input(...), rather
than input(...), and then convert the return value from a string to
whatever you need it to be.


When you see the net take the shot
When you miss your shot shoot again
When you make your shot you win!

Just remember
Offense sells tickets
But defense wins championships!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top