-1

I have simple code. And i have problem: "Unresolver reference 'a' more...". This problem occurs at the third if function.

enter image description here

And I have to declare it outside of the abcd function, otherwise each time in the while function a will be set to the value I declare and not according to the if. How to do it?

def abcd(s, e):
if s<0.72:
    if e>30:
    a=0
    return a

else:
    a=0
    return a
else:
    if a == 1:
       a = 1
       return a
    else:
       a=1
       return a
while True:
abcd
Brown Bear
  • 19,655
  • 10
  • 58
  • 76
F.Fipoo
  • 111
  • 1
  • 4
  • 12
  • 2
    Please fix your indentation. – Daniel Roseman Sep 16 '17 at 21:39
  • 1
    Python **does not have variable declarations**. You can use a `global a` directive in your function, if you want the function to consider `a` as the global `a`, otherwise, since you assign to `a`, the compiler marks `a` as *local*. – juanpa.arrivillaga Sep 16 '17 at 21:40
  • Possible duplicate of [Using global variables in a function other than the one that created them](https://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them) – wwii Sep 16 '17 at 21:44

1 Answers1

0

You can set a = 0 in the beginning of abcd, like so:

def abcd(s, e):
   a = 0
   if s<0.72:
       if e>30:
          a=0
          return a
       else:
          a=0
          return a
   else:
       if a == 1:
          a = 1
          return a
       else:
          a=1
          return a
while True:
   s = int(input("type value for s "))
   e = int(input("type value for e "))
   print( abcd(s, e )  )

However you can simplify it:

def abcd(s, e):
   if s<0.72:
       return 0
   return 1

while True:
   s = int(input("type value for s"))
   e = int(input("type value for e"))
   print( abcd(s, e )  )