Functions in Math
April 17, 2018
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)
Recent Entries
- Data-Driven Enhancements February 08, 2025
- Building a Dynamic Prompting App February 06, 2025
- Sphaîra February 05, 2025