-2

I am converting pseudocode in the python program but I am stuck and giving me error for

REPEAT

and

UNTIL age >= min AND age <= max.

Please let me know how can I fix it. Thank you in advance

BEGIN
REPEAT
min = 18
max = 60
OUTPUT "what is your age?"
INPUT age
IF age < min or age > max THEN
 OUTPUT “Error - age must be between 18 and 60 "
ELSE
  OUTPUT "Age is accepted "
ENDIF
 UNTIL age >= min AND age <= max
 END
FabioSpaghetti
  • 790
  • 1
  • 9
  • 35
fida
  • 1
  • 1

5 Answers5

2
min = 18
max = 60
age = int(input('What is your age? '))
while not (min <= age <= max):
    print('Error - age must be between 18 and 60')
    age = int(input('What is your age? '))
print('Age is accepted')

I guess.

sashaaero
  • 2,618
  • 5
  • 23
  • 41
  • @IMCoins I guess he just wants this task to be done and asking for code he has would take a while. But I agree that we should let them understand that this is not "Do for me" website. – sashaaero Aug 07 '19 at 10:05
  • I don't know what's disturbing me the most in your comment. The fact that it `would take time and he just wants the job done` or the fact that you agree with me that we should make people understand this is a helping site, and not a `Do for me` code site, but still : we do it anyways. – IMCoins Aug 07 '19 at 10:10
  • @IMCoins it's like I've made an exception. Dunno why. – sashaaero Aug 07 '19 at 10:13
1

The REPEAT ... UNTIL <condition> construct is something like a do ... while-loop in many languages. Python does not have something like this.

I can think of two solutions for this:

while True:
    ...
    if <condition>:
        break

or

continue_loop = True
while continue_loop:
    ...
    if <condition>:
        continue_loop = False
MofX
  • 1,569
  • 12
  • 22
0

You could do while loop with a if condition to breakout when criteria is met.

min = 18
max = 60


while True:
    print("what is your age?")
    INPUT age # or some other command reading from input

    if age < min or age > max:
        print(“Error - age must be between 18 and 60 ")
    else:
        print("Age is accepted ")

    if age >= min AND age <= max:
        break

Have put the min/max and output values outside of loop as there is no reason to re-set it each time. You could also break out from loop in the else block where you program is happy with inserted value.

Rob
  • 415
  • 4
  • 12
0

This might be a simple example for the code you have written.

    min = 18
    max = 60
    print("Enter your age")
    age = int(input())
    if(age < min or age > max):
        print("Error : Age must be between 18 and 60")
    else: print("Age is accepted and you age is "+ str(age))
Nitin
  • 11
0

Repeat until could be defined like that:

min = 0
max = 100
while true:
    age = int(input('age: '))
    if (min < age < max):
        print('age {0} accepted'.format(age))
        break;
    print('age should be between {0} and {1}'.format(min, max))
    age = int(input('age: '))
nuggetier
  • 172
  • 2
  • 6