1

I'm a bit of a noob; just wondering whats wrong here

__author__ = 'Ghossein'

def double(x):
    x = 0.0
    d = 0.0
    d = x + x
    return (d)

def trip_dub(x):
    t = 0.0
    t = double(x) + double(x) + double(x)
    return(t)

def main():
    result=0.0
    result = double(trip_dub(1.0))
    print(result)

I want to print 'result' but when i run the code nothing comes up (no errors either). If i put print(result) on it's own line then it says result is not defined.

2 Answers2

3

You never call main. Normally, you'd have a:

if __name__ == '__main__':
    main()

line at the end of the script. The __name__ == '__main__' bit will be True only if the module is run as the main script (as opposed to being imported from another module).

mgilson
  • 300,191
  • 65
  • 633
  • 696
2

You have to actually call the function. Throw this at the end of your script:

if __name__ == '__main__':
    main()
Alec
  • 1,399
  • 4
  • 15
  • 27
  • No problem! <3 (By the way: the conditional is so that you can import the functions and use them in other scrips *without* printing until you call the function.) – Alec Jul 12 '16 at 04:00