1

Please tell how can I correct this code

1

Hi, I am 12 years old and I am in 8th Class my teacher gave me this task to write a program which will ask to enter a number greater than 100 and then it will check whether it is greater than 100 or not , if not so it will apply a for loop and if it is greater than 100 so it will show that "the number is greater than 100"

buran
  • 13,682
  • 10
  • 36
  • 61
AT_Arush
  • 17
  • 1
  • 6
  • @sagi look at the image he has in his question – gerda die gandalfziege Feb 01 '22 at 12:45
  • 2
    Please paste your code here and don't use images. – sagi Feb 01 '22 at 12:46
  • You should ask for input **inside** the loop (here you infinitely tell the user they are wrong without giving them a chance to correct), also if you test as exit condition of the `while`, no need to test again with `if` – mozway Feb 01 '22 at 12:47
  • 2
    Welcome to Stack Overflow. Please, check [ask]. Don't post images of code, errors, data, etc. Copy/paste as formatted text block. – buran Feb 01 '22 at 12:47
  • I addition to comments above - check the condition on this line `if a <=10:` – buran Feb 01 '22 at 12:48
  • Obviously you need to get a new input somewhere ... you don't. Why? Use pythontutor.com or a debugger to step through your code to see the code flow. You also may need to fix <=100 to be consistent with your input-texts. – Patrick Artner Feb 01 '22 at 12:55

1 Answers1

1

This is what your code should look like:

a = int(input("Enter a value bigger than 100: "))

# loop ends if the number is bigger than 100 otherwise it will run forever
while a <= 100: 

    print("try again")
    # asks the use for input 
    a = int(input("Enter a value bigger than 100: "))

print("Congrats, you entered a value bigger than 100")
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69