2

This is what I want, but for an integer. I am not allowed to use break or continue to exit loops.

# basically I need this, but with an int(input('please enter a number')) ask = input('Would you like to play Steal or Deal [y|n]? ') while ask not in ('y', 'n'): print ("Please enter either 'y' or 'n'") print('') ask = input('Would you like to play Steal or Deal [y|n]? ') 

1 Answer 1

1

You could try to convert the string to an int and catch the exception:

def is_number(s): try: int(s) return True except ValueError: return False ask = input('please enter a number: ') while not is_number(ask): print ("no, a number!") print('') ask = input('please enter a number: ') 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.