DEV Community

Anjali Chaturvedi
Anjali Chaturvedi

Posted on

Python Prowess: Day 2

Funny got to know python has indent sensitivity along with the case sensitivity!

Here is the program to calculate XOR from 1 to n

def xor(n) :
    if n % 4 == 0 : 
        return n 


    if n % 4 == 1 : 
        return 1


    if n % 4 == 2 : 
        return n + 1


    return 0

if __name__ == "__main__" :
    n = 5
    print(xor(n))
Enter fullscreen mode Exit fullscreen mode

Output - 1
🌼Please comment if you have any suggestions or encouraging words.🌼

Top comments (3)

Collapse
 
fortniteskinhacker profile image
LILHOODIERAGGER

How hard is it to use python language

Collapse
 
iceorfiresite profile image
Ice or Fire

Python is one of the easier languages to learn

Collapse
 
ic1101virgo profile image
Anjali Chaturvedi

Not so much actually and if you know any other language like C++, Java etc I'll be simpler! Go ahead :P