If Turn is equal to 1 the first if condition will be True, so Turn will get set to 0. But then execution passes to the second if condition, which is now True, so Turn will get reset to 1.
The sensible way to handle that is to use elif, as others have mentioned. Alternatively, you can duplicate the print into both branches, and put an early return in the first branch. The elif approach is better because it avoids the code duplication, and it's also good style to avoid early returns if you can. But I'll show you the code anyway:
def SomeFunction():
global Turn
if Turn == 1:
#some code
Turn = 0
print Turn
return
if Turn == 0:
#some code
Turn = 1
print Turn
Turn = 1
for i in range(10):
SomeFunction()
output
0
1
0
1
0
1
0
1
0
1
BTW, the usual Python convention is to use lower case for simple variable and function names. Capitalized and CamelCase names are used for class names. Of course, you don't have to follow this convention, but if ypou don't it makes your code look strange when viewed with most syntax highlighting software, so it's unnecessarily confusing to the rest of the Python community.
See PEP 0008 -- Style Guide for Python Code for details.
Actually, you can alternate a value between zero and one without using an if statement. The trick is to use the exclusive-OR operator, ^:
def SomeFunction():
global Turn
Turn ^= 1
print Turn
Turn = 1
for i in range(10):
SomeFunction()
This results in the same output as before.
If a variable only ever takes on the values zero and one you should consider making at a boolean instead, and have it alternate between False and True, as that can lead to more readable code. You can alternate it with:
Turn = not Turn
and you can use a boolean value in arithmetic expressions, where it will behave just like 0 or 1, although some people don't like doing that, and consider it less readable.
I guess I should also mention that you should try to avoid using global. It can be handy, but use of modifiable globals breaks the modularity of code. It's not a big deal for small scripts, but you will really appreciate modular design when you write large complex programs.
1. Perhaps you want to use anelifthe second time.