Skip to content

🐍 Program 137: Count Equal Values #160

@iamAntimPal

Description

@iamAntimPal

🐍 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 QuestionsenhancementNew feature or requestgood first issueGood for newcomersquestionFurther information is requested

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions