+ 2
Hello, how can improve it? Three numbers are given. Display “yes“ if there are identical among them, otherwise display “ERROR”
23 ответов
+ 12
Arnesh , 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 , an other question:
if a == b or a == c or b == c or b == a or c == a or c == b:
# why checking for < a == b > and also for < b == a >? this is a duplication.
so this code is doing the same but has half the size:
if a == b or a == c or b == c:
+ 9
if len((a, b, c)) != len({a, b, c}):
print('yes')
else:
print('error')
+ 7
def isequal(*args):
for i in args:
if args.count(i)>1:
return True
return False
if isequal(a,b,c, d, e, f, g,...):
print("Yes")
+ 6
Arnesh , do a few tries to see how it is working. If you have any doubts, present a few samples.
+ 4
Please tell me what you want to improve in it...
a, b, and c are assigned different values.
"or" returns true if one of the statement is true (or both true).
All variables are assigned 1,2,3 which aren't equal. Therefore, it prints "error".
If you will replace any of them which is true like:-
if a==a:
Then, it will print "yes"
+ 4
Your question is not clear to me.
Are you asking about your question.
I think there's isn't any problem with your code. Ok, so you were asking about mentioning someone in the answer. 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 answered your question. The person whom you mention will be notified when you mention him/her
+ 4
Giulia Merlin , you are absolutely right. maybe Михаил can give us the answer?
+ 3
Short, easy to read and understand:
a, b, c = 1, 2, 3
print('yes') if a == b == c else print('error')
+ 3
# if there are more numbers to compare you can use all()
lst = [a,b,c]
print('yes') if all(i == a for i in lst) else print('error')
+ 3
Narcode Blood gang, please don't ask questions in the question threads of other users.
About your question:
*You* can!
Have you taken a look at our tutorials?
They start easily, and if something's confusing, you'll sure find the solution in the comments or by a search in this forum.
You can also search this forum for beginner advice, there's a lot going around.
https://www.sololearn.com/discuss/1316935/?ref=app
+ 3
'If there are identical among them' in my opinion can be only interpreted in the way that not all have to be equal.
+ 2
you can put them in a set ,since you cant have multiple numbers that are similar in a set,then check for the len of the set if the length of the set is 1 or 2 then print "yes" if it is 3 then print "error"
like this...
my_set={a,b,c}
if len(my_set) < 3:
print("yes")
else:
print("ERROR")
or you can make it shorter
my_set={a,b,c}
print("yes") if len(my_set) < 3 else print("ERROR")
+ 1
Added to description
+ 1
How can I add your name to the answer?
+ 1
꧁༒Rishabh༒꧂ thanks
+ 1
Please who can teach me programming ?
+ 1
Sorry but maybe I have misunderstood the question
All three Numbers must be equal in order to get "yes" or only two of them?
With the "or" statement you can have yes even if one of the three numbers Is different from the others.
0
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 thanks
0
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 It looks better
0
Lothar what if a==b!=c?