Profile Photo

Web Development

  • Public Group
  • 3 days, 10 hours ago
  • 12

    Posts

  • 10

    Members

How to fix invalid literal for int() with base 10 in Python?

2 voices
2 replies
  • Author
    Posts
  • #71694
    Ikenna dike
    Participant
    Rank: Newbie
    Up
    2
    Down
    ::
    Share with friends!

    Hello all.
    Please I have challenge on an assignment. I am getting this error invalid literal for int() with base 10 while trying to run a function I created to calculate BMI. I did a code like this:

    height = input("enter your height in m: ")
    weight = input("enter your weight in kg: ")
    h = int(height)
    w = int(weight)
    BMI = w/(h*h)
    print(int(BMI))

    Please assist.

    #71705
    Ozoemena
    Participant
    Rank: Gallant Sojourner
    Up
    1
    Down
    ::

    Hi Ike.
    Please try float your height and weight as seen below and you’ll be fine.

    h = float(height)
    w = float(weight)
    #71706
    Ikenna dike
    Participant
    Rank: Newbie
    Up
    0
    Down
    ::

    Thank you, that worked!

You must be logged in to reply to this topic.