-2

I want it so that if you input the gross income as anything less than 0, it will ask you to re-input the answer until it gets a positive number but I'm a bit stuck on it.

GrossIncome = float(input("Enter your gross income: "))
   
GrossIncome == <0:
     
print("sorry, could you please repeat that?")
     
print(GrossIncome)
        
if GrossIncome >0:
    break

this is what i have right now and if anyone can help me that would be great

George Imerlishvili
  • 1,816
  • 2
  • 12
  • 20

3 Answers3

0
GrossIncome = float(input("...?")
while(GrossIncome < 0):
    GrossIncome = float(input("bad input")
print(GrossIncome)
Nicolas
  • 51
  • 12
0

One way to do this would be:

GrossIncome = float(input("Enter your gross income: "))

while GrossIncome < 0:
   print("sorry, could you please repeat that?")
   GrossIncome = float(input("Enter your gross income: "))

print(GrossIncome)

This does not take care of the error when entering anything else than a float as input, but you get your desired behaviour.

Kins
  • 547
  • 1
  • 5
  • 22
0
run = True
while run:
    grossincome = float(input("Enter your gross income: "))
    if grossincome > 0:
        run = False
    else:
        print("please enter value more than 0")

print(f"You enterd {grossincome}\n finished")

George Imerlishvili
  • 1,816
  • 2
  • 12
  • 20