DEV Community

loading...

Python Prowess: Day 2

ic1101virgo profile image Anjali Chaturvedi ・1 min read

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.🌼

Discussion (3)

pic
Editor guide
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 Author

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