r/pythonhelp • • Feb 02 '23

having trouble with this code

planets = {
"mercury": 5429,
"venus": 5243,
"earth": 5514,
"mars": 3934,
"jupiter": 1326,
"saturn": 687,
"uranus": 1270,
"neptune": 1638
}
planet_name = input('Enter the name of a planet:')
if planet_name in planets:
print("this planet has a density of:" planets[planet_name])
else:
print("unrecognised planet")

2 Upvotes

1 comment sorted by

1

u/Fusion_000 Feb 02 '23 edited Feb 02 '23

Syntax error Try this

planet_name = input('Enter the name of a planet:')
if planet_name in planets:
    print("this planet has a density of:", planets[planet_name])
else:
    print("unrecognised planet")