Which can be simplified to:
length=0
while length and not 100 < length < 1000:
length=getInput('Enter the Length','150')
Main Topics
Browse All TopicsI need to ask again for a INPUT from the user if the user typed wrongly
for example
I ask the user for Input by
length = getInput("Enter the Length","100",)
here getInput is a ABAQUS Function it returns the value if the user pressed OK Button and 'None' if the user pressed CANCEL button.
now the problem is if the user enters some absurd values say 1000000 then i need to ask again the user for a correct value
the correct value is (100 - 1000).
I had written a small program but it is not working.
can anybody help me out for a solution.
##########################
#Program
##########################
length = getInput('Enter the Length for the Rectangle','150')
for i in range(0,1):
...if length != None and length !=" " and length>=100 and length<=1000 :
......break
...else:
......i=0
......length= getInput('Enter the Length','150')
......continue
print "Length=" ,length
##########################
#End
##########################
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi Experts,
SiliconLength,SiliconHeigh
inputTuple = [SiliconLength,SiliconHeig
for i in range(0,len(inputTuple)):
...if inputTuple[i] == None and inputTuple[i] == ' ' :
...... SiliconLength,SiliconHeigh
...else:
...... break
Hi ashok3sep. This sounds like a new question. For several reasons we ask that you start a new Question rather than extending the current Question.
If we have given you the answer you wanted to "Loop repitition" please accept the answer. If not, please let us know what is needed or missing.
And please open a new question for "test all the varaibles in a tuple...".
Bob Gailer
Page Editor
OK I now see how your "new" question is a variation of what you started with. I missed that. There is a fine line around how much "work" to get done within the scope of one Question. Let's continue with this and see when we agree to start a new Question.
The for loop as written will always break at the first element of inputTuple since inputTuple[i] == None and inputTuple[i] == ' ' is always False.
You really need 2 loops here, an outer loop to keep asking for input until the user gets it right, and an inner looop to test each item of the tuple. Example:
good = False # inner loop changes this to indicate success
for tries in range(10): # limit number of user attempts to avoid endless loop
..inputTuple = getInputs(areas,label = 'Specify Block Dimensions',dialogTitle ='Testing')
..for item in inputTuple: # inner loop examines each item till one fails the test
....if item == None or item == '':
......break
....else: # all items passed
......good = True
..if good:
break
Now unpack the tuple:
SiliconLength,SiliconHeigh
"how can i test the variables Individually?" I take this to mean "how can I give the user the name of the variable that he entered wrong?" True?
List comprehension can often replace a for loop resulting in simpler code:
for tries in range(10):
..inputTuple = getInputs(areas,label = 'Specify Block Dimensions',dialogTitle ='Testing')
..if [1 for item in inputTuple if item != None and item != '']:
....break
..else:
....print "10 strikes - you're out"
That will not fly. You test that one input is OK, not all of them.
Which can be simplified to:
for tries in range(10):
inputTuple = getInputs(areas,label = 'Specify Block Dimensions',dialogTitle ='Testing')
if sum(1 for item in inputTuple if item)==len(inputTuple):
SiliconLength,SiliconHeigh
# test individual values
if test_ok:
break
print "Not all vars entered correctly, try again."
else:
print "10 strikes - you're out"
Note: line with sum() is for Python 2.4, for previous version use sum([1 for item in inputTuple if item]).
Thanks ramrom and mish33 for your fast responses.
let me say the pseudo code of what i need in the loop
1.) first is test in the GUI that all the fields are not EMPTY and not NONE
2.)then i test all the values entered by the user are within the limits .
for example
lets say the user entered
SiliconLength = 100 ;
SiliconHeight = 1000; and so on.......
first i test whether the values in the fields are filled and not EMPTY or NONE
then i take the value of SiliconLength and check whether 100 is allowed or not
if 100 is not allowed and i need a value between 50 - 75 then i need again to say the user that the value entered for silicon is wrong and ask the user again for hte input.........
Hope this is clear and understandable..
i am working araound to find a logic behind the problem but it is little difficult for me at the moment.
With regards,
Freedom.
INPUT_LIMITS = (
(10,100, 'SiliconLength'),
(10,20, SiliconHeight'),
(1,5, 'klebstoffHeight'),
(100,200, 'length'),
(50,150, 'height'),
(0,180, 'angle1'),
(0,90, 'angle2'),
(0,180, 'angle3'),
(0,90, 'angle4')
)
for tries in range(10):
inputTuple = getInputs(areas,label = 'Specify Block Dimensions',dialogTitle ='Testing')
if sum(1 for item in inputTuple if item)==len(inputTuple):
# test individual values
all_fine = True
for item, (low,high,name) in zip(inputTuple, INPUT_LIMITS):
try: x = int(item)
except:
print "Expecting int, got '%s' for %s" % (item, name)
n = 0
if not (low<=x<=high):
all_fine = False
print "%s shall be in [%d..%d] range" % (name, low, high)
if all_fine:
break
print "Not all vars entered correctly, try again."
else:
print "10 strikes - you're out"
Business Accounts
Answer for Membership
by: mish33Posted on 2005-05-06 at 10:58:36ID: 13946621
length=0
while length is not None and (length<100 or length>1000):
length=getInput('Enter the Length','150')