+ 2

Hello, how can improve it? Three numbers are given. Display “yes“ if there are identical among them, otherwise display “ERROR”

https://code.sololearn.com/cco3YY84FB15/?ref=app

10th Jul 2020, 11:06 AM
Михаил
28 Respuestas
+ 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:
10th Jul 2020, 4:13 PM
Lothar
Lothar - avatar
+ 9
if len((a, b, c)) != len({a, b, c}): print('yes') else: print('error')
10th Jul 2020, 5:58 PM
HonFu
HonFu - avatar
+ 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")
10th Jul 2020, 11:17 AM
Arnesh
Arnesh - avatar
+ 6
Arnesh , do a few tries to see how it is working. If you have any doubts, present a few samples.
10th Jul 2020, 3:35 PM
Lothar
Lothar - avatar
+ 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"
10th Jul 2020, 11:19 AM
Arctic Fox
Arctic Fox - avatar
+ 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
10th Jul 2020, 11:36 AM
Arctic Fox
Arctic Fox - avatar
+ 4
Giulia Merlin , you are absolutely right. maybe Михаил can give us the answer?
12th Jul 2020, 7:51 AM
Lothar
Lothar - avatar
+ 3
Short, easy to read and understand: a, b, c = 1, 2, 3 print('yes') if a == b == c else print('error')
10th Jul 2020, 2:30 PM
Lothar
Lothar - avatar
+ 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')
10th Jul 2020, 2:38 PM
Lothar
Lothar - avatar
+ 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
11th Jul 2020, 12:39 PM
HonFu
HonFu - avatar
+ 3
'If there are identical among them' in my opinion can be only interpreted in the way that not all have to be equal.
12th Jul 2020, 7:54 AM
HonFu
HonFu - avatar
+ 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")
11th Jul 2020, 12:05 PM
MichaelOwen
MichaelOwen - avatar
+ 1
Added to description
10th Jul 2020, 11:30 AM
Михаил
+ 1
How can I add your name to the answer?
10th Jul 2020, 11:31 AM
Михаил
10th Jul 2020, 11:41 AM
Михаил
+ 1
Please who can teach me programming ?
11th Jul 2020, 12:28 PM
24th Nation
24th Nation - avatar
+ 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.
12th Jul 2020, 12:03 AM
Giulia Merlin
Giulia Merlin - avatar
10th Jul 2020, 11:41 AM
Михаил
10th Jul 2020, 11:55 AM
Михаил
0
Lothar what if a==b!=c?
10th Jul 2020, 2:31 PM
Arnesh
Arnesh - avatar