let's design a program with chain conditionals we want to build a program that calculates an object's weight on different planets we have the formula for this already weight equals mass time gravity so if we know an object's weight on Earth we can divide by Earth's gravity to get the mass and then once we have the mass we can just multiply by the gravitational force of whatever Planet we're interested in our starter code here calculates an object's weight on Mars we take the gravitational force on Mars which is 3. 7 m/s squ then we ask for the weight of the object on earth and then we plug those two numbers into our formula to get the weight on Mars I'm thinking I want to round this number though so it's a bit easier for the user to look at there's definitely a built-in function for this okay looks like it's just called round and it takes two arguments the number to be rounded and the number of decimal places to round two that's looking a lot cleaner now I want to make this work for other planets too not just Mars so we're going to want an input function call that ask the user to enter a planet name we'll assign that to the variable planet and then we'll use a conditional to assign the value of gravity let's start with the Mars case that we already had before I start my conditional I want to make sure to initialize my variable gravity to a default value let's say zero here probably makes sense we'll want our condition to be Planet equals equals the string Mars if this evaluates to true then we want to set gravity to 3. 7 which is the gravitational force on Mars so we indent that assignment statement inside that if Branch there are a lot of planets so let's just start with a few of them we'll do Mars Mercury Venus and Jupiter Mercury's gravitational force is also 3.
7 so we can just use the ore operator to turn this into a compound condition that checks if the planet is Mars or Mercury next we want to check if the planet equals Venus this is related to the previous condition and it's mutually exclusive with it the planet can't both be Mars and Venus so so it makes sense to use an L if Branch here if the planet equals equals Venus then we want to set gravity to Venus's gravitational force then we have the Jupiter case which is another Branch now let's test that conditional if I enter Mars it's giving the same weight that I had before so that must be correct and Mercury should give the same answer and then Venus's gravitational force is bigger so its weight should be bigger and then Jupiter should be even bigger still oh wait uh that's a zero maybe that means gravity still has this default value zero when we do the calculation and maybe this Branch isn't actually executing let me test that hypothesis by adding some temporary debugging print statements I'll add one inside this Jupiter L if Branch so I can see if this branch is actually getting executed and then maybe I'll print down here what the value of gravity is right before I calculate the weight uh interesting so it is hitting that Branch because it's executing this print statement and it says that the value of gravity is zero that's bizarre because if it's executing this Branch it should be executing this assignment statement which means gravity should be 23. 1 o wait I see the bug I use the equality operator not the assignment operator so this is checking if gravity equals equals 23. 1 instead of assigning 23.