lundi 10 mai 2021

What is happening to my python program, please tell me? How both if else statement can be true?

I am currently using python3.9. I have coded a python block of code in which I have put an if else Condition but when I enter my input such as 15 then both conditions became true like the following. I want to know how an if-else condition can be true in both case. You can see it in following screenshot so that you can understand well and help me in this.:

Here is the Image I am giving you for inspecting.

x = input("Enter a number: ")
x = int(x)

def my_func(y):
    for i in range(1, y):
        if y % i == 0:
            print("It is consecutive")
        elif y < 2:
            print("It is smaller than 2")
        else:
            print("It is prime")
            break


my_func(x)

Aucun commentaire:

Enregistrer un commentaire