Help with code

This is the place for queries that don't fit in any of the other categories.

Re: Help with code

Postby micseydel » Fri Nov 01, 2013 12:29 am

You need to read a basic tutorial about scope, functions, and passing arguments around as well as returning values. If you have trouble while you're learning that you're welcome to ask specific questions.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Help with code

Postby helpmepass » Fri Nov 01, 2013 12:30 am

I do have trouble learning this. I've read it. I don't get it. That is why I'm here. It's due in a few hours so can I get some help?
helpmepass
 
Posts: 8
Joined: Wed Oct 30, 2013 7:09 pm

Re: Help with code

Postby micseydel » Fri Nov 01, 2013 12:43 am

Your function output_sum() is unaware of either of those variables. You need to pass them as arguments. Here's some code that I hope illustrates the issue.

Bad
Code: Select all
>>> def f():
   print x

   
>>> def g():
   x = 7
   f()

   
>>> g()

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    g()
  File "<pyshell#7>", line 3, in g
    f()
  File "<pyshell#3>", line 2, in f
    print x
NameError: global name 'x' is not defined


Good
Code: Select all
>>> def f(x):
   print x

   
>>> def g():
   y = 7
   f(y)

   
>>> g()
7
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Previous

Return to General Coding Help

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests