Exercise
Double Value Function
Objective
Develop a Python function named "double" to calculate and return an integer that is twice its input. For example, double(7) should return 14.
Example Python Exercise
Show Python Code
# Define the function double which calculates and returns twice the input integer
def double(num):
return num * 2 # Return the double of the input number
# Main function to call double and display the result
def main():
result = double(7) # Call the double function with the number 7
print("The double of 7 is {}".format(result)) # Print the result
# Call the main function to execute the program
main()
Output
The double of 7 is 14
Share this Python Exercise