ashok3sep
asked on
Loop repitition
I 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
########################## ########## ####
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
##########################
Which can be simplified to:
length=0
while length and not 100 < length < 1000:
length=getInput('Enter the Length','150')
length=0
while length and not 100 < length < 1000:
length=getInput('Enter the Length','150')
ramrom: No it can't. You didn't run that.
OOPS - well here's a new release candidate:
length=10 # or any value outside desired range
while length and not 100 <= length <= 1000:
length=getInput('Enter the Length','150')
length=10 # or any value outside desired range
while length and not 100 <= length <= 1000:
length=getInput('Enter the Length','150')
ASKER
Hi Experts,
SiliconLength,SiliconHeigh t,klebstof fHeight,le ngth,heigh t,angle1,a ngle2,angl e3,angle4 = getInputs(areas,label = 'Specify Block Dimensions',dialogTitle ='Testing')
inputTuple = [SiliconLength,SiliconHeig ht,klebsto ffHeight,l ength,heig ht,angle1, angle2,ang le3,angle4 ]
for i in range(0,len(inputTuple)):
...if inputTuple[i] == None and inputTuple[i] == ' ' :
...... SiliconLength,SiliconHeigh t,klebstof fHeight,le ngth,heigh t,angle1,a ngle2,angl e3,angle4 = getInputs(areas,label = 'Specify Block Dimensions',dialogTitle ='Testing')
...else:
...... break
SiliconLength,SiliconHeigh
inputTuple = [SiliconLength,SiliconHeig
for i in range(0,len(inputTuple)):
...if inputTuple[i] == None and inputTuple[i] == ' ' :
...... SiliconLength,SiliconHeigh
...else:
...... break
ASKER
How can i test all the varaibles in a tuple for None or empty string
ASKER
after that how can i test the variables Induvidually
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
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
ASKER
thanks for your suggestions ramrom
I have increased the points from 100 to 250 for the question and that is the reason i had asked for this question
if you wish to have in another thread then i can also have it in anothere thread.
With regards,
Freedom
I have increased the points from 100 to 250 for the question and that is the reason i had asked for this question
if you wish to have in another thread then i can also have it in anothere thread.
With regards,
Freedom
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 t,klebstof fHeight,le ngth,heigh t,angle1,a ngle2,angl e3,angle4 = inputTuple
# 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]).
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]).
Oh yeah. My head is not working this AM like I'd like it to. Sigh.
But let's keep the [] for the comprehension: sum([1 for item in inputTuple if item]).
But let's keep the [] for the comprehension: sum([1 for item in inputTuple if item]).
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
while length is not None and (length<100 or length>1000):
length=getInput('Enter the Length','150')