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))
Output - 1
🌼Please comment if you have any suggestions or encouraging words.🌼
Latest comments (3)
How hard is it to use python language
Not so much actually and if you know any other language like C++, Java etc I'll be simpler! Go ahead :P
Python is one of the easier languages to learn