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.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1390
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
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1390
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: conor100, W3C [Linkcheck] and 6 guests