Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with returning variables

vbchguy87vbchguy87 Posts: 4Member
Hello i am a n00b with python i need help. i cannot get the code below to work


def main():
t_s = input('what were the t_s?')
s_t(t_s)
c_t(t_s)
t_t(s_t,c_t)
print 'your t_t ', t_t


def s_t(value):
return float(value)*2

def c_t(value):
return float(value)*3


def t_t(val1,val2):
t_t = val1+val2


main()

then i run it and get the error
TypeError: unsupported operand type(s) for +: 'function' and 'function'



HELP


Comments

  • bubbatremellbubbatremell Posts: 39Member
    : def main():
    : t_s = input('what were the t_s?')
    : s_t(t_s)
    : c_t(t_s)
    : t_t(s_t,c_t)
    : print 'your t_t ', t_t
    :
    :
    : def s_t(value):
    : return float(value)*2
    :
    : def c_t(value):
    : return float(value)*3
    :
    :
    : def t_t(val1,val2):
    : t_t = val1+val2

    : then i run it and get the error
    : TypeError: unsupported operand type(s) for +: 'function' and
    : 'function'

    t_t(s_t,c_t) is the problem. s_t and c_t are functions. If you want to call them, use t_t(s_t(x), c_t(x)). Your line is passing the actual functions as parameters-- not the return values.

    Also, s_t and c_t return values, but you aren't storing them anywhere. You might try either
    s = s_t(t_s)
    c = c_t(t_s)
    t_t(s, c)
    or
    t_t(s_t(t_s), c_t(t_s))

  • vbchguy87vbchguy87 Posts: 4Member
    Thanks a lot got it working
Sign In or Register to comment.