+ INFORMATION

Share on social networks!

How much do you weigh on Mars?

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

Screenshot 2021 04 28 at 10.56.19

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 functionstr” and chaining it with a little message.

Result we get

AiJjaPxSBl0Fr4Ny1Rp7hs3PWnEZm5E22ve7yBdRGUxCdnd2pP rbotbNFCNFPvqk2DWRa8d tldRKUyFWnIzmpmamXr5LVulcIDugtzrLb8jwpYZhNJpetFgoeSnVOme zN0ylnoHX25S 3A

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:

how to calculate weight on mars

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

Jz1pbDhDuGmgOP50A 3JrZMQ3H1YWNRO9Weub4UNTMgBgEQ94iYl4NzMgMwYvGSwkai3DBi8Z5QgRUuWIpH0J4Vv9GQGu1c72OHvsUe39WYRdPd6AjZLrvJyqpqLVn48TP36A9RkuKvz5 cVyw
lXoBueZ1Fhdo51Pd9
5WbVbaxn4WH1c tcMy73Sl2p5ZZFWuAH0zQMvId9qKrFx2m0G4h8j0swHM08IXI1FOh9BmxejS JVRFTV1OASnKcG jPR6vNhVe0MnEwhKj1NgQjkvfqk zjBzVL5Nf0UbRhzOtIGKPTrM mbA

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!

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SA as the person responsible for this website. The purpose of collecting and processing personal data is to respond to the query made as well as to send information about the services of the data controller. Legitimation is the consent of the interested party.
You can exercise your rights of access, rectification, limitation and deletion of data in compliance@grupomainjobs.com as well as the right to file a claim with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find in our Web page
marter-in-python

Leave a comment