0

So i'm having problems with append function. It just doesn't add words to the list . What im trying to do is account login , where you can add new account what you can use when you login. This is just an example script put it works the same way. I'm trying to add new word to my mapp (example: Guido) and then i can use that word "guido" to get my program to print yay . So here's my example script:

mapp = ["example"]



example1 = raw_input("Enter Username: ")
if example1 in mapp:
    print "yay"
else:
    print ("Forgot Username eh?")
    example = raw_input("Enter New Username: ")
    if example not in mapp:
        mapp.append(example)

So if anybody can help , help is appreciated . Thanks

8
  • How are you checking whether something has been added to the list? Commented Jan 28, 2013 at 17:26
  • 1
    What do you mean 'it doesn't work?' What is your expected outcome? Commented Jan 28, 2013 at 17:26
  • it's working. what output you want? Commented Jan 28, 2013 at 17:29
  • Given what you're doing, you might consider using a set rather than a list. A set seems to be a more appropriate data structure for your intentions here. Additionally, you can get rid of the if example not in map check. To use it, update your code to mapp = set(['example']), remove the if example not in mapp line and change append to add. Commented Jan 28, 2013 at 17:31
  • 1
    My expected outcome is what its supposed to do. - you say that like it is obvious - we are not mind readers and your code isn't clear. You need to tell us what it is supposed to do if you want help. Commented Jan 28, 2013 at 18:15

2 Answers 2

1

Simply add the last line to your script, and see that it is in fact working. (Edited to add a while loop that will keep the program running forever).

mapp = ["example"]


while True:
    example1 = raw_input("Enter Username: ")
    if example1 in mapp:
        print "yay"
    else:
        print ("Forgot Username eh?")
        example = raw_input("Enter New Username: ")
        if example not in mapp:
            mapp.append(example)

    print mmap
Sign up to request clarification or add additional context in comments.

2 Comments

So why i can't use word "example" to get my program to print yay after i have added it to the map .
Because your program terminates (stops running) when it reaches the end. If you'd like to make it continue, check out my edit above (give me a second)
0

It does add words (one word, because you only do it once) to the list. Add print mapp to the end and you'll see.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.