In previous posts we have seen the logical operators of Python, the keywords and the predefined functions. Well, today we are going to put into practice what we have learned with a curious exercise to calculate what we would weigh on Mars.
The steps we must follow are explained to us Maria Jose Pena, Director of Master of Advanced Programming in Python for Big Data, Hacking and Machine Learning in EIP to be able to calculate our weight on Mars.
We start with this code

Where weightonearth It is a float type variable that collects by keyboard the weight we have on earth.
weightOnMars It is the variable where we convert the weight of the Earth into the weight we would have on Mars with a simple formula that we have located in the wonderful Google.
And finally we print on the screen weightOnMars converting it into text with the predefined function “str” and chaining it with a little message.
Result we get
But we're going to give it a spin. Let's put a condition about the weight so that it sends us one message or another depending on the value of the variable weightOnMars:

In the first condition (if), we say that if weightOnMars is greater than or equal to 35, print the message.
If the first condition is not met, go to the next one (elif) where if weightOnMars is greater than or equal to 25 and less than 35, print the message, here we are already using the and operator that we saw in the previous post, logical operators and in the keywords.
Finally, if none of the above is true, it means that pesoEnMarte is less than 25 and therefore the last message is printed.
Examples of the above
Did you find it interesting how to calculate your weight on Mars? We hope you try to calculate it. You can tell us in comments. We read you!