+ 1

What did I do wrong? (Explanation in comments)

newadj = input() if newadj not in list(adj): adj.append(newadj) sleep(1) os.system("cls") print("Here is the list with your new entry:\n \n") print(list(adj)) print("\n \nYour adjective has been added.") sleep(3) os.system("cls") else: print("\n \nSorry that is already in the list.") sleep(3) os.system("cls")

2nd Jun 2017, 9:33 AM
Spock
Spock - avatar
9 Answers
+ 1
I tried your code and it works fine. I had to remove some of your lines, but the if works well like this: adj = ["a", "aa", "aaa", "b", "bb", "bbb"] newadj = input() if newadj not in list(adj): adj.append(newadj) print("Here is the list with your new entry:\n \n") print(list(adj)) print("\n \nYour adjective has been added.") else: print("\n \nSorry that is already in the list.") Try to check the indentation, maybe it's the problem. "else" should have the same indentation level as "if" to work properly
2nd Jun 2017, 12:17 PM
Lana
Lana - avatar
0
I am trying to write a function that takes user input, checks a list to make sure its not included, and adds it to the end of the list if its not in the list or throws an error message and restarts if it is included. Due to limited room I did not include the rest of the function.. but this is in a while loop. For whatever reason python seems to completely ignore the if and else statements after getting user input.
2nd Jun 2017, 9:38 AM
Spock
Spock - avatar
0
hmm, it's not an indentation issue... I use atom. it would tell me if that were the case. Also when it executes this block of code it is not throwing any errors. it just seems to ignore the if statements after getting user input and then goes back to the beginning of the program.. I'd post it all in the code playground.. but I'm at work and on my phone.. I'll post it/link it when I get home and have internet.
2nd Jun 2017, 12:31 PM
Spock
Spock - avatar
0
https://code.sololearn.com/c8R55oNk4DZ1/?ref=app Here is the full program so far. nLook at the functions addadj() and addnoun().. after it gets the user input and assigns it to a variable (newadj & newnoun) it seems to ignore the rest of the function where it will jump back to the function menuscrn(). And I would suggest copying and pasting this into a real IDE maybe IDLE.. The code playground just executes it badly.
3rd Jun 2017, 6:20 AM
Spock
Spock - avatar
0
Just woke up, haven't had a chance to try it yet. I will as soon as I get to work though. that will be here in about 2 and a half hours. I'll let you know.
3rd Jun 2017, 3:34 PM
Spock
Spock - avatar
0
@DK 's It worked! Thank you. I didnt realize I needed to specify the variable multiple times to be able to check each string. But that makes sense as the "or" statements would create a whole new condition check. Thanks again.
3rd Jun 2017, 6:11 PM
Spock
Spock - avatar