+ 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

28th Jul 2019, 6:48 AM
Manjit Kumar
Manjit Kumar - avatar
4 Respuestas
+ 6
while True: try: a=int(input()) except: continue else: If a<0: continue else: break
28th Jul 2019, 6:55 AM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 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
28th Jul 2019, 6:55 AM
ΛM!N
ΛM!N - avatar
+ 1
Manjit Kumar I mean four spaces I wrote the code, so you can use it
28th Jul 2019, 6:59 AM
ΛM!N
ΛM!N - avatar
0
Михаил Горчанюк worked 😁😁 only thing i was doing wrong was... taking input outside of the loop
28th Jul 2019, 7:00 AM
Manjit Kumar
Manjit Kumar - avatar