0

Here is the statement:

def recursive(y):
    if y < 10:
        return y
    else:
        z = raw_input("Please enter a number: ")
        recursive(z)

x = raw_input("Please enter a number: ")
t = recursive(x)

print t

Whenever I run this, if I enter a number equal to or above 10, it prompts me to enter a number again. If I enter a number less than 10, it still tells me to enter a number; however, if I enter less than 10, shouldn't the if y < 10 be true and it will return that number?

Drew D
  • 127
  • 6

2 Answers2

0

You have 2 issues:

  • You do not return the result of your call
  • You do not cast your raw_input (which is a string) as an int.

Here's the corrected version:

def recursive(y):
    if y < 10:
        return y
    else:
        z = raw_input("Please enter a number: ")
        return recursive(int(z))
DevShark
  • 7,878
  • 7
  • 30
  • 54
-1

as always because you are nto returning in your else branch ...

def recursive(y):
    if float(y) < 10: # also you need to make this a number
        return y
    else:
        z = raw_input("Please enter a number: ")
        return recursive(z) #this is almost always the problem with these questions
Joran Beasley
  • 103,130
  • 11
  • 146
  • 174