0

for example, i have this code

def awal():
    a = 2

def akhir():
    print(a)
awal()
akhir()

well i got error that said a is not defined?
i used global, same error
use return, same error
any idea why?

Edited by Dihyan: well i know this is silly question, but please:( im kinda new to python 3

4
Contributors
3
Replies
29
Views
4 Months
Discussion Span
Last Post by Shankar.Shiv
0
def awal():
  global a
  a=2
  return a

def akhir():
  a = awal()
  print(a)

akhir()

You just miss one thing just check my code..

def awal():

  a=2
  return a

def akhir():
  a = awal()
  print(a)

akhir()

This is second code without global variable..

Edited by Shankar.Shiv

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.