-3

so they aren't anything special that I would ask I just wanna ask that are they any alternative for input because input only accepts str and if I change the type like for example

float(input(enter any number here:))

if the user input other thing that isn't float it would be an error but what I want is a message to pop-up and tell the user to only enter float if it detects that anything that the user type isn't float. ps. sorry for bad grammar I'm not a native speaker and I'm just pretty much new to the programming community I would be very appreciated if you help me thankyou.

TheSavageTeddy
  • 204
  • 1
  • 13
MPH_08
  • 1
  • 1

1 Answers1

1

you can use try and except to catch an error and use a while loop to get input again

while True:
   try:
      a = float(input("enter any number here:"))
      break
   except:
      print("Error! Please enter Valid Float NUmber")
Vignesh
  • 1,553
  • 1
  • 10
  • 25
TheSavageTeddy
  • 204
  • 1
  • 13
  • Thank you very much I don't even know that there are except, try in python I just realize it after saw it in the book. – MPH_08 Nov 03 '20 at 03:39