0
def m():
    m1 = input()
    m1.lower()
    if m1 in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']:
        return m1
    else:
        m()
f= m()

Here, value of f updates as long as if statement is executed, when else is executed which calls the function itself. So, when the second time if is executed(after else) the value of f is not updating and giving out "none"

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 5
    You need to return something even when you execute function recursively: `return m()` – Olvin Roght Dec 29 '20 at 16:41
  • 2
    Google "python recursive none" and find at least 20 duplicates. How did you miss those? – user2390182 Dec 29 '20 at 16:47
  • 1
    Python strings are immutable. ` m1.lower()` does not modify m1, but returns a new string, which you then ignore. You need to write `m1 = m1.lower()` to get the result you're expecting. – Frank Yellin Dec 29 '20 at 17:02

1 Answers1

-1

@Olvin Rought is correct. You need to add return m() inside the else. If you dont add the return the code will run recursively but will not actually return anything once it enters the else statement

def m():
    m1 = input()
    m1.lower()
    if m1 in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']:
        return m1
    else:
        return m()
f= m()
TeddyBearSuicide
  • 1,377
  • 1
  • 6
  • 11