How do I make this user input change the calculation in this if statement?

Question:

How do I make this user input change the calculation in this if statement?

  print("I have information for the following planets:n")

    print("   1. Venus   2. Mars    3. Jupiter")
    print("   4. Saturn  5. Uranus  6. Neptunen")
 
    weight = 185

    planet = 0

    Planet_gravity = 0



    Venus = 0.91
    Mars = 0.38
    Jupiter = 2.34
    Saturn = 1.06
    Uranus = 0.92
    Neptune = 1.19

    Planet_name = input("Planet name: ")
    print(Planet_name)

    if Planet_name == Venus:
        Planet_gravity += 0.91
    elif planet == Mars:
        Planet_gravity += 0.38
    elif planet == Jupiter:
        Planet_gravity += 2.34
    elif planet == Saturn:
        Planet_gravity += 1.06
    elif planet == Uranus:
        Planet_gravity += 0.92
    elif planet == Neptune:
    Planet_gravity += 1.19


    planet_weight = weight * Planet_gravity

    print("Gravity" + " " + (str(planet_weight)))

I would like the if statement to take into account the chosen user input and use it in the calculation to calculate planet weight. Everytime I type the name of the planet in the shell, I just get back 0 instead of the correct calculation. It’s supposed to multiply the planet gravity by the weight to get the "planet_weight" as I call it or how heavy the person is on the planet.

Asked By: Benjamin G

||

Answers:

Your if statement is incorrect. If u check string, the literals need be in quotes

if planet_name == 'Venus':
    Planet_gravity += 0.91
elif planet_name == 'Mars':
    Planet_gravity += 0.38

and so on…

Another thing u can use f string for print ur out.

print(f"Gravity is : {planet_weight}")

print string with numbers

Regards

Answered By: Matheus Brito
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.