-2

The code below runs and prints out the values returned from the two functions test_value(address) and checkRepeatCount(address) when i try to add the two value returned i None as the result. Anyway to fix this?


def check(address):
   
   ## define point variables
    pass_invalid_char = test_value(address)
    pass_repeat_count = checkRepeatCount(address)

    if pass_invalid_char == False:
        return print("Invalid character")
    else:
        pass
    
   total = pass_invalid_char+pass_repeat_count
   print(total)



check("hello")

Function 1 test_value

def test_value(value):
    return print(30)

Function 2 checkRepeatCount

def checkRepeatCount(value):
    return print(20)

Thats how im returning the function values

Zayne komichi
  • 408
  • 4
  • 11
  • 1
    You code is not reproducible, what are `test_value` and `checkRepeatCount`? – mozway Mar 16 '22 at 14:52
  • 2
    The function `print()` always returns `None`, and also any function with no explicit return will return `None`. So your function is always returning `None`. Did you mean to do `return total` insead of `print(total)`? – Green Cloak Guy Mar 16 '22 at 14:53
  • 1
    In short, your function does not return anything. It merely prints and exits. You must have a `return` line for it to pass something back to the caller. (Note that you can have it `print(total)` and `return total` if you want both behaviors) – JNevill Mar 16 '22 at 14:56
  • both functions return a number, im trying to get the total number of the two added together. When i run the two individually they work, they are being imported from their own file – Zayne komichi Mar 16 '22 at 14:58
  • I was returning a print statement with the value thank you – Zayne komichi Mar 16 '22 at 15:02
  • 1
    you should add the entire code including that of the mentioned functions so that people can reproduce the problem. – Hasan Aga Mar 16 '22 at 15:04
  • @jNevil could you post something so i can close this question your answer got me to the solution – Zayne komichi Mar 16 '22 at 15:05
  • @Zaynekomichi ok, but why not edit this question and make it better instead? – Hasan Aga Mar 16 '22 at 15:06
  • Let me do that!!! – Zayne komichi Mar 16 '22 at 15:07
  • Does this answer your question? [Why is the output of my function printing out "None"?](https://stackoverflow.com/questions/7053652/why-is-the-output-of-my-function-printing-out-none) – JonSG Mar 16 '22 at 15:08
  • not really let me post what my error was – Zayne komichi Mar 16 '22 at 15:12
  • 1
    I'm glad to hear you got it working :) – JNevill Mar 16 '22 at 15:36

1 Answers1

1

In both functions was returning a print statement with value

def test_value(value):
    return print(30)

I was supposed just to return the number on its own like so

def test_value(value):
    return 30
Zayne komichi
  • 408
  • 4
  • 11