Defining num1 doesn't actually define h. The definition of num1 just says that, when you call num1, it will assign to the global name h. If h doesn't exist at that time, it will be created. But defining num1 isn't sufficient to create h.
You need to ensure that h exists before num2 is called. You can do that by assigning to h yourself, or calling num1.
>>> num2()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in num2
NameError: name 'h' is not defined
>>> h = 3
>>> num2()
3
>>> del h
>>> num2()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in num2
NameError: name 'h' is not defined
>>> num1()
>>> num2()
7
num1forhto be defined.