Issues with if/elif control in Python

I’m a beginner and i’m struggling with if function as it doesn’t work. Please help ! Thanks =)

planet = input(str( " 1. Venus 2. Mars 3. Jupiter 4. Saturn 5. Uranus 6. Neptune" ))
weight = input(“Your weight”)
weight = int(weight)
planet_gravity = 0
if planet == “1”:
planet_gravity = 0.38
elif planet == “2”:
planet_gravity = 0.38
elif planet == “3”:
planet_gravity = 2.34
elif planet == “4”:
planet_gravity = 1.06
elif planet == “5”:
planet_gravity = 0.92
elif planet == “6”:
planet_gravity = 1.19


Please see the following link for details about setting up a question (namely a reasonable title, a link to the lesson, code formatting and categorisation)-

Can you explain what issue you have with your code and what isn’t working as expected.

Thanks for the advice i’m quite new to this community i’ll try better next time. So i’m currently working on my Python 3 project, but the “if” and “else” function doesn’t seem to work once the “planet” variable received it input it doesn’t transfer to the “if” function but directly to “print” instead. So For example if my planet = 1 then i want my planet_gravity = 0.38 but if i entered 1 as my input for planet then it prints 0 for planet_gravity

It sounds like none of the conditions in your if statement are being met (so the line where you assign 0 to planet_gravity is the only one that’s run).

You need to make sure your user input matches the exact string added via input. This would be a strict text match so any other characters, including whitespace e.g. from pressing spacebar, would mean the condition is not met.

You could try calling print with planet to ensure it contains a string with the required format of the following style “1” (" 1" or "1 " for example do not match “1”).

A more robust method might be to call input again if the string does not match that text format but that might be tricky to set-up without getting further in the course. Maybe something to keep in mind.

wow thanks alot man i really appreciate it