0

I have seen lots of answers to similar questions but none that are using OOP in python.

I need to write a piece of code that restricts the user to entering a number between 0 and 300 within a method, then call it later on.

This is the method used inside my class:

    def setMinutes (self, minutes):

        movieLength = str(0 - 300)

        for movieLength in movieLength:
            print('***debug: movieLength' + movieLength + 'submitted length' + minutes)

            if minutes == movieLength:
                self.minutes = minutes
                return True

        return False

and this is the code being used to call the function:

    bolNeedMinutes = True
    while bolNeedMinutes:

        minutesInput = input("Enter length in minutes (0 - 300):") 
        if objMovie.setMinutes(minutesInput):
            bolNeedMinutes = False

This works, however, the only valid input is zero. Any help / criticism is much appreciated !

  • `str(0-300)` will return the string `"-300"`. You need something like `while not 0 < movieLength <= 300:`. – Tim Roberts Nov 03 '22 at 22:37
  • Also need `minutesInput` to be an `int`. `input()` returns a `str`. I really recommend learning to use a debugger to go through the code line-by-line looking at the types and values of each variable to understand what you are doing. – Mark Tolonen Nov 03 '22 at 22:45

0 Answers0