Assigning the answer of a function to a variable?(in python 2.4.4)
Question:
def BSformula(num1):
"""my formula"""
(num1 - 2.0) * (2 / num1)
def main():
number = input("value")
answer = BSformula(number)
print(answer)
main()
When I run it it always prints “None”
>>>
value: 6
None
>>>
How would I assign the answer to a variable?
or can I only print it in the def BSformula??
Answers:
Just use the keyword return
.
def BSformula(num1):
"""my formula"""
return (num1 - 2.0) * (2 / num1)
def BSformula(num1):
"""my formula"""
(num1 - 2.0) * (2 / num1)
def main():
number = input("value")
answer = BSformula(number)
print(answer)
main()
When I run it it always prints “None”
>>>
value: 6
None
>>>
How would I assign the answer to a variable?
or can I only print it in the def BSformula??
Just use the keyword return
.
def BSformula(num1):
"""my formula"""
return (num1 - 2.0) * (2 / num1)