PDA

View Full Version : Quick Python Help??



Joe-G
10-28-2013, 03:25 PM
Getting ready to submit an assignment, but I have a quick concern that I've been having difficulty solving.

In my program, only certain inputs (A range of numbers that are allowed to be entered into the prompt) are allowed. If a number outside of this range is entered, that specific program repeats over and over.

My question is, how do I get that part of my program to repeat when some other invalid character is entered?

Ie. The prompt asks to enter a number from 1-3.

Any number less than 1 or greater than 3 reloops that portion. But If i enter any letter, symbol, a space, etc the program just quits.

Any quick help?

Hakkola
10-28-2013, 03:27 PM
I'm not going to do it for you but what you need are;
if
else

This should have everything you need

The general Python if-else syntax is

if condition :
indentedStatementBlockForTrueCondition
else:
indentedStatementBlockForFalseCondition


Meaning Math Symbol Python Symbols
Less than < <
Greater than > >
Less than or equal ≤ <=
Greater than or equal ≥ >=
Equals = ==
Not equal ≠ !=

http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/ifstatements.html

roopi
10-28-2013, 03:31 PM
So are you saying that when you enter a non number the program is quitting and you would like it to prompt for the number again?

I don't know python but form a quick search you just need to verify if it is a number as your first step. Maybe isdigit function?

Joe-G
10-28-2013, 03:55 PM
Originally posted by roopi
So are you saying that when you enter a non number the program is quitting and you would like it to prompt for the number again?

I don't know python but form a quick search you just need to verify if it is a number as your first step. Maybe isdigit function?

That was the problem. Any non-number character would produce a Traceback/ValueError. The way I had it set up was that it would look for an integer, I guess it didnt know what to do with anything else.

Anyways, I think I may have figured it out. Thanks for the input!

:goflames: