-1

I am trying to get this code to repeat if the second function does not return False and seem to be having problems.

Furthermore, The if statement in the second function is not accepting the integers that I am passing when it should be (i.e when I pass 1-8). Perhaps range() is not appropriate here?

def askanything():
    choice = (int(input("Which battery? (1-8):")))
    batchoice(choice)

def batchoice(bat):
    if bat in range(1-9):
        return True
    else:
        print("sorry, selection must be between 1-8")
        askanything()
Josmolio
  • 13
  • 4

1 Answers1

0

You need a while loop to continue asking the question until the condition is met. You don't want to be calling a function within a function call. One way to simplify this is to just put it all in one function:

def askanything():
    done = False
    while not done:
        choice = (int(input("Which battery? (1-8):")))
        if(choice in range(1,9)):
            done = True
        else:
            print('Sorry, selection must be between 1-8')
Kewl
  • 3,327
  • 5
  • 26
  • 45