+ 3

list operators

https://code.sololearn.com/cnEzL45zquNl/#py Can Someone Explain (A) Why Is It Not Appearing as 'Groundnut Or Butter' Instead 'ingredient[4] or ingredient[5]' (B) Why I Am Not Able To Split The Statement Within else

5th Apr 2020, 8:49 AM
Mani
Mani - avatar
13 ответов
+ 2
Mani working fine now. https://code.sololearn.com/c3XJxgD14t9S/?ref=app edited: what you mean by your second question.kindly explan it
5th Apr 2020, 8:51 AM
Muhammad Bilal
Muhammad Bilal - avatar
5th Apr 2020, 9:04 AM
Muhammad Bilal
Muhammad Bilal - avatar
+ 2
Hey split() is not working as you have added the parenthesis. So remove the brackets in the y variable and then add a semicolon ";".
5th Apr 2020, 9:51 AM
Abhiraj Ghumare
Abhiraj Ghumare - avatar
+ 1
But what about the 'split()' Can even correct me where did I go wrong ??
5th Apr 2020, 8:54 AM
Mani
Mani - avatar
+ 1
What you want to do explain ? I could'nt get your point.
5th Apr 2020, 8:55 AM
Muhammad Bilal
Muhammad Bilal - avatar
+ 1
Explanation: you are printing ingredients[4] as it is not its value. eg. a=2 print("a") This prints a character a . So to print its value you have to write it in print statement without quotation marks. Like this. a=2 print(a) Output is 2
5th Apr 2020, 8:58 AM
Muhammad Bilal
Muhammad Bilal - avatar
+ 1
Broi, I understand that one. Thanks again for explaining my mistake. But I have used a list () statement in top of my code and split() statement at the end of code. Notice !! . The thing I am trying to figure out why isn't split() doesn't work ??
5th Apr 2020, 9:03 AM
Mani
Mani - avatar
+ 1
Oh !! Got it
5th Apr 2020, 9:08 AM
Mani
Mani - avatar
+ 1
Finally figured it out. Thanks a lot Muhammad Bilal
5th Apr 2020, 9:11 AM
Mani
Mani - avatar
+ 1
You're welcome
5th Apr 2020, 9:14 AM
Muhammad Bilal
Muhammad Bilal - avatar
+ 1
you should change all if condition into elif just no 1 condition if ..and last condition else x = ("Welcome To The Supermarket") print(list(x)) ingredients = ['Wheat','Rice','Corn','Dal','Groundnut','Butter'] if 'Wheat' in ingredients: print("Its Packed") elif 'Rice' in ingredients: print("We Don't Sell Rice") elif 'Corn' in ingredients: print("You Have Recieced an Discountl") elif 'Dal' in ingredients: print("Do You Need moong Dal Or massor dal") elif 'Butter' in ingredients: print("You Dont Have Enough Money, \nSo Select Either,ingredients[4],'or',ingredients[5] ") print('Milk' not in ingredients) elif 'Milk' in ingredients: print("not again") else: y = ("Thanks For Shopping. Do Visit Again") print(y.split(" "))
7th Apr 2020, 12:58 AM
Syed Ahmed Raza Shah
Syed Ahmed Raza Shah - avatar
0
I was just trying to make use of split() and list() in one of my statements. list () is working but split() doesn't ??
5th Apr 2020, 8:57 AM
Mani
Mani - avatar
0
(A) cause you wrote it within quotes, you shall write it outside quotes.... (B) split is working dude...
6th Apr 2020, 10:49 AM
Varun Vaswani
Varun Vaswani - avatar