I used sublist in the code but the code is not working properly. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

I used sublist in the code but the code is not working properly.

I wrote a program to practice append() function, It's like this, I wrote some names in a list, if you are in the list then it prints "(Your name), I know who you are" if not it asks you if you are my good friend or not, if Yes, it will add your name to the 3rd sublist of the list and will print "(Your name), you are added to the list" if not it prints "(Your name), you are no good friend of Manthan's", if you are on the list it prints "(Your name), I know who you are". Instead of the above functions, even you are in the list, it does not execute the else statement as it should work. Thank you! https://code.sololearn.com/c15B23522sFh/?ref=app

8th May 2020, 8:42 AM
Manthan Gohel
Manthan Gohel - avatar
4 Answers
+ 2
Instead of "or" and "or" in elif it should be "and" & "and" ,since when you enter for example Abhinav ,it will return False for name not in list[0] because Abhinav is there but when it checks next condition name not in list[1] Abhinav is not there so it will return True and since you are using "or" operator ,statement will be True
8th May 2020, 8:51 AM
Abhay
Abhay - avatar
+ 2
Hey Manthan Gohel. SoloLearn input system is a bit different. Try inputting like this : Arb Yes Output will be : Enter your name : Arb Are you a good friend of Manthan's (Type Yes or No) : Yes Arb, you are added to the list. You have to give multiple inputs separating by a new line :))
8th May 2020, 8:55 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 2
Abhay Thanks man, I didn't really paid attention to that.
8th May 2020, 10:00 AM
Manthan Gohel
Manthan Gohel - avatar
+ 2
Arb Rahim Badsa No, it's not sololearn playground's fault. See the answer of Abhay.
8th May 2020, 10:02 AM
Manthan Gohel
Manthan Gohel - avatar