0
Code doubt
If I write this: familia=["A","B","C"] familia[0]= "D" if ("A” and "B" and "C") in familia: print ("ok") else: print ("ouch!") print (familia) Output is “ok” (i thought that the second line replace value [0] But I realize that writing this down: familia=["A","B","C"] familia[0]= "D" if ("H” and "B" and "C") in familia: print ("ok") else: print ("ouch!") print (familia) In this case Output is still “ok” I dont understand why is “ok” if “H” is not in familia list...
6 odpowiedzi
0
in any statement you should always type the entire phrase, it is not like in human language do. That's the core concept of programming.
Yes, it is not possible to resume it or to make it shorter in this case because you used AND operator.
+ 2
# yes you can do something like:
allin = lambda check, group: all(v in group for v in check)
familia = ['A','B','C']
if allin(('A','B','C'),familia):
print('ok')
else:
print('ouch!')
# output: ok
if allin(('H','B','C'),familia):
print('ok')
else:
print('ouch!')
# output: ouch!
+ 1
because you should write:
if "A" in familia and "B" in familia and...
+ 1
its because you are missing double equal sign ==, in this case your actual if block will apply the correct one which is "C" in familia, so its ok 🙂
what you should do is <<if "H" in familia and "B" in familia and "C" in familia>>
but what you did is
if "H" and "B" and "C" in familia which leads to semantic error, the IDE does not show any error but the output is unlogical.
I hope you got the point.
familia=["A","B","C"]
familia[0]= "D"
if "H" in familia and "B" in familia and "C" in familia:
print("ok")
else:
print("ouch!")
print(familia)
0
Matias Tardini
familia=list(input().split(" "))
if('A'in familia and'B'in familia and'C' in familia):
print("ok")
else:
print("not ok")
0
so this kind of expression cant be resumed?
if “A” in familia and “B” in familia “C” in familia...
can you say for example This list (list items) in this group...