Created
January 28, 2017 16:03
-
-
Save AliSajid/74acd18c19bbeefeafc2af43412ed5cc to your computer and use it in GitHub Desktop.
An elegant solution to a trivial exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
# Define the Square function | |
def square(n): | |
return n * n | |
# Define the Cube function | |
def cube(n): | |
return n ** 3 | |
# Define the square root function | |
def root(n): | |
return math.sqrt(n) | |
# Defined a "main" function that ties everything up in a neat package | |
def main(): | |
m = int(input("Enter your number: ")) | |
print("The square of {0!s} is {1!s}".format(m, square(m))) # I used the String.format method to concatenate strings. | |
print("The cube of {0!s} is {1!s}".format(m, cube(m))) # I also used the "!s" directive to force conversion to string implicitly. | |
print("The square root of {0!s} is {1!s}".format(m, root(m))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment