Skip to content

Instantly share code, notes, and snippets.

@wray
Created February 13, 2016 13:42
Show Gist options
  • Save wray/a6555c41154642196d9f to your computer and use it in GitHub Desktop.
Save wray/a6555c41154642196d9f to your computer and use it in GitHub Desktop.
#
# An example program to calculate weight on moon after a certain number
# of years. We are assuming someone who currently weighs more than 150 will only
# gain .5 pounds a year, while lighter individuals will gain 2 pounds a year.
# This is the concept we just learned. Defining a function in python.
# We use a function to calculate moon weight, mWeight after a certain number
# of years, years.
def moon_weight(current_weight,years):
pounds_per_year = 2
if current_weight > 150:
pounds_per_year = 0.5
future_weight = current_weight + (pounds_per_year * years)
mWeight = future_weight * 0.165
return mWeight
# Now, let's test this method a few times. Note how we are now "calling"
# the method we defined.
print("For someone who weighs 80 pounds now, they will weigh this on the moon after 15 years:")
new_weight = moon_weight(80,15)
print(str(new_weight))
print("")
print("For someone who weighs 160 pounds now, they will weigh this on the moon after 17 years:")
new_weight = moon_weight(160,17)
print(str(new_weight))
print("")
print("For someone who weighs 40 pounds now, they will weigh this on the moon after 30 years:")
new_weight = moon_weight(40,30)
print(str(new_weight))
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment