Names declared with global keyword have to be referred at the file level. This is because of the global scope. If no global statement is being used the variable with the local scope is accessed.
Hence, in the above code, the statement succeeding the statement global x informs Python to increment the global variable x
Hence, the output is 6 i.e. 5 + 1 which is also the value for global x. When x is reassigned with the value 3 the local x hides the global x and hence 3 printed.
(2 marks for explaining the output) (Only 1 mark for explaining global and local namespace.)