-2

If value is 1-100 it stops program If value <1 or >100 i need to print (try again) and loop back to top. This what i got atm

n1 = 0
n1 = int(input("Enter number between 1-100: "));
print ("your number is: ", n1);
while n1 > 100 or n1 < 0:
  print("Try again");
blackstar
  • 25
  • 6

2 Answers2

-1

Try this,

while True:
    n1 = 0
    n1 = int(input("Enter number between 1-100: "));
    if n1 < 100 and n1 > 0:
        break
    else:
        continue

and please don't use ; end of your code.

Kushan Gunasekera
  • 7,268
  • 6
  • 44
  • 58
-1

This is now how python works First of all no need to initiate n1 and then assign input value to it You should have used if instead of while

while True :
             try :
                   n1 = int(input ())
             except :
                   print ("enter numerical value")
              if n1<1 or n1>100 : 
                    print ("try again")
              else :
                       break
Mind indentation
  • Your formatting introduces a syntax error and is hard to read. You removed the input prompt. See answers to previous questions for improvement. – Prune Jun 26 '19 at 17:19