While true :
D = input(‘enter 0 to exit’)
If D == 0:
Break
Print(‘loop ended’)
This loop isn’t breaking and is asking ‘enter 0 to exit’ again and again. Is there something wrong with the code.
While true :
D = input(‘enter 0 to exit’)
If D == 0:
Break
Print(‘loop ended’)
This loop isn’t breaking and is asking ‘enter 0 to exit’ again and again. Is there something wrong with the code.
input(...) returns a string but you’re checking for the integer 0. If you write this instead: if D == "0" (with quotes around 0), then it should work.
In order to convert a string to an integer, you can use int(D). So, for example:
D = input("enter 0 to exit")
N = int(D)
if N == 0:
...
However, if the string D cannot be converted to an integer (for example if the string is “abc”), then this will throw an error. You can catch that error with try-except.