+ 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
13 Antworten
+ 2
Mani
working fine now.
https://code.sololearn.com/c3XJxgD14t9S/?ref=app
edited: what you mean by your second question.kindly explan it
+ 2
Mani
This is how split works.
https://code.sololearn.com/cl3WhHawve6v/?ref=app
+ 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 ";".
+ 1
But what about the 'split()'
Can even correct me where did I go wrong ??
+ 1
What you want to do explain ?
I could'nt get your point.
+ 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
+ 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 ??
+ 1
Oh !! Got it
+ 1
Finally figured it out. Thanks a lot Muhammad Bilal
+ 1
You're welcome
+ 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(" "))
0
I was just trying to make use of split() and list() in one of my statements. list () is working but split() doesn't ??
0
(A) cause you wrote it within quotes, you shall write it outside quotes....
(B) split is working dude...