Python Forum
How to reject "invalid" input in Python3.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to reject "invalid" input in Python3.7
#2
I see an indentation error there. You have to be careful with the indentations.

Try this solution

while True:
    try:
        height = float(input("Input your height in meters: "))
        weight = float(input("Input your weight in kilogram: "))

        userBmi = round(weight / (height * height), 2)

        print("User BMI: {}".format(userBmi))
        break
    except ValueError:
        print("Incorrect, Try again")
Reply


Messages In This Thread
RE: How to reject "invalid" input in Python3.7 - by FranSPG - Feb-08-2019, 12:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020