Demo entry 6780106

Max

   

Submitted by anonymous on Dec 22, 2018 at 16:18
Language: Python 3. Code size: 1.8 kB.

def inputVerifFunc(self, question, intLock, boolLock, coordLock, numLB=(-math.inf), numUB=(math.inf)):
        print(question)
        inputValid = False
        while not inputValid:
            answer = input(">> ")
            if intLock:
                try:
                    answer = int(answer)
                    if answer < numLB:
                        print("Invalid input. Please enter a number above",numLB)
                    elif answer > numUB:
                        print("Invalid input. Please enter a number below",numUB)
                    else:
                        inputValid = True
                except:
                    print("Invalid input. Please re-try and enter a number. ")
            elif boolLock:
                if answer.upper() == "Y":
                    answer = True
                    inputValid = True
                elif answer.upper() == "N":
                    answer = False
                    inputValid = True
                else:
                    print("Invalid input. Please try again and make sure you enter 'Y' or 'N'.")
            elif coordLock:
                try:
                    answer = answer.split(",")
                    self.answerX, self.answerY = int(answer[0]), int(answer[1])
                    if not(self.answerX > (self.gridSize-1) or self.answerX < 0 or self.answerY > (self.gridSize-1) or self.answerY < 0):
                        inputValid = True
                        print("")
                    else:
                        print("\nInvalid input. Please enter a co-ordinate within the grid (i.e: between 0 and " + str(self.gridSize-1) + ")")
                except:
                    print("\nInvalid input. Please try again.")

        return answer

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).