Skip to content

Commit

Permalink
Create Mars_Weight.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sksalahuddin2828 authored Jul 10, 2023
1 parent 2c0c7b7 commit cb22738
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Mars_Weight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use constants
MARS_MULTIPLE = 0.378

def main():
earth_weight_str = input('Enter a weight on Earth: ')

# Get the numeric value since input() returns a value in string form
earth_weight = float(earth_weight_str)

# Having a variable for each piece of information is a good habit
mars_weight = earth_weight * MARS_MULTIPLE
rounded_mars_weight = round(mars_weight, 2)

# Note the string concatenation!
print('The equivalent weight on Mars: ' + str(rounded_mars_weight))

if __name__ == '__main__':
main()


#--------------------------------------------------------------------------------------------

# Mars Weight Solution
# There are three key stages to solving this problem:

# 1. Getting the Earthling's weight from them, which I need the input function for.

# 2. Converting the Earthing's weight from a string to a number so I can do math with it.
# I use the float function to do this, since the weight isn't necessarily a whole number

# 3. Calculating the weight on Mars, which I do by multiplying the Earth weight by 0.378.
# To make the program easy to read, I store this number in a constant called MARS_MULTIPLE.

# Check out the solution code to see all of these stages in action.

0 comments on commit cb22738

Please sign in to comment.