+ 2
I want this code to ask to input the number again after getting a result in python
a = int(input("enter number") if a < 0: print("negative number") I know a while loop will do the work.. but can't understand how to use while loop here. When the user will first input a number then he will get the result and program will stop. But i want it to ask to enter the number again to check
4 Answers
+ 6
while True:
try:
a=int(input())
except:
continue
else:
If a<0:
continue
else:
break
+ 1
Add this in the beginning of code and then add tab in the beginning of other lines:
while True:
The code will become like this:
while True:
a = int(input("enter number: "))
if a < 0:
print("negative number")
else:
break
+ 1
Manjit Kumar I mean four spaces
I wrote the code, so you can use it
0
ĐĐžŃ
аОл ĐĐŸŃŃĐ°ĐœŃĐș worked đđ
only thing i was doing wrong was... taking input outside of the loop