Plutonic Rainbows

Functions in Math

I’ve been looking again at functions and how they work. They are great for simple math but can do a lot more besides. With that in mind, here is a simple way of multiplying numbers with user input. Remember to tell Python to use float when handling numbers.

def calc(value1, value2):
	return value1 * value2
	
print "\nLet's multiply two numbers.\n"	

value1 = (float(raw_input("Enter a number: ")))
value2 = (float(raw_input("Enter another number: ")))


answer = calc(value1, value2)

print "\nThe answer is {0:.2f}.\n".format (answer)