-
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
PythonPython Interview QuestionsPython Interview QuestionsenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersquestionFurther information is requestedFurther information is requested
Milestone
Description
🐍 Program 137: Count Equal Values
📌 Description
Create a function that takes three integer arguments (a, b, c) and returns the amount of integers which are of equal value.
💡 Code Example
def equal(a, b, c):
# Create a set from the three numbers to count unique values
unique_values = {a, b, c}
# If there is one unique value, return 3 (all are equal)
if len(unique_values) == 1:
return 3
# If there are two unique values, return 2 (two are equal)
elif len(unique_values) == 2:
return 2
# If there are three unique values, return 0 (none are equal)
else:
return 0
# Examples
print(equal(3, 4, 3)) # ➞ 2
print(equal(1, 1, 1)) # ➞ 3
print(equal(3, 4, 1)) # ➞ 0✅ Output
2
3
0
🧠 Explanation
- The function uses a set to count the number of unique values.
- Based on the size of the set:
- If there's one unique value, all numbers are equal (return 3).
- If there are two unique values, two numbers are equal (return 2).
- If there are three unique values, no numbers are equal (return 0).
Metadata
Metadata
Assignees
Labels
PythonPython Interview QuestionsPython Interview QuestionsenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersquestionFurther information is requestedFurther information is requested