Reputation: 101
how can i write a function that takes 2 integer parameters, a and b. Inside the function I need calculate the value of x using the formula below (where the term 2a indicates that 2 is multiplied by a). I'm quite lost with doing this can someone please give me a hint on how to start this code in python?
Upvotes: 2
Views: 487
Reputation: 27577
Here is how:
def x(a, b):
return (b+(b**2-1)**0.5)/(2*a)
In python, we use **
for power symbols.
Upvotes: 0
Reputation: 605
You can use the below method to achieve your goal.
# remember to import math
x = lambda a, b: (math.sqrt(b**2 - 1) + b)/(2 * a)
Now you can use this function:
x(5, 10) # gives 1.99498743710662 (roughly)
Upvotes: 3