Respuesta :

Answer:

Here is the function:

def NumRepeats(num1,num2,num3): #function definition

    count = 0   #to count number of items repeated

    if(num1 != num2 and num1 != num3 and num2 != num3): #if none of the items are repeated

         count = 0 #sets count to 0

    elif num1==num2==num3: #if an item is repeated more than once

         count = 2 #sets count to 2

    elif num1 == num2 or num2 == num3 or num1 == num3: #if any of the items is repeated

         count = 1  #sets count to 2

    return count #returns the value of count

Explanation:

In order to check the working of the above method you can call this method and print the result produced by the method :

print(NumRepeats(5,9,4))

print(NumRepeats(5,9,5))

print(NumRepeats(5,5,5))

If you want to take input from user then you can use the following statements:

num1 = int(input("Enter integer 1: "))

num2 = int(input("Enter integer 2: "))

num3 = int(input("Enter integer 3: "))

print(NumRepeats(num1,num2,num3))

Lets take one of the above examples to understand the working of the method:

print(NumRepeats(5,9,4))

Here

num1 = 5

num2 = 9

num3 = 4

if(num1 != num2 and num1 != num3 and num2 != num3)

num1 != num2 means num1 is not equal to num2

num1 != num3 means num1 is not equal to num3

num2 != num3 means num2 is not equal to num3

this if condition checks if all the values are not repeated. So this evaluates to true because :

5 is not equal to 9

5 is not equal to 4

9 is not equal to 4

So the statement inside this if condition is executed which is:

count = 0

Now return count returns this value i.e. 0

So the output of this program is 0

The screenshot of the program along with the output is attached.

Ver imagen mahamnasir

Otras preguntas