
November 16th, 2012, 04:45 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 4
Time spent in forums: 49 m 43 sec
Reputation Power: 0
|
|
Thank you for the tip about using coding to keep the white space, i appreciate it. I guess I'm just having a big problem understanding how to use the variables. I am taking an online class and basically attempting to teach myself how to do all of this, but i'm finding it hard to understand all the rules. I have yet another assignment that involves me rewriting the following so it shows the value of x instead of an error.
Code:
def add_one(number):
x = 1
number = number + x
print(number)
#The following is then entered in IDLE
>>>add_one(5)
6
>>>x
NameError: name 'x' not defined
The above is from my instructor. I have rewritten it one way...
Code:
def add_one(number):
return number + x
#Then I run the program and enter the following into IDLE
>>>x = 1
>>>add_one(5)
6
>>>x
1
but i feel that i've taken the easy way out by inserting x=1 into IDLE. I'm willing to use the first one as an answer in my assignment, but I'm responsible for providing 2 different ways to print x properly, and I can't (on my own) figure another way. Everything I try ends up with an error for x. If you or anyone else could explain (like you would to a complete idiot since that's what I'm feeling like right now lol) to me the rules for making the program receive the value of x. Again please excuse my rookie ways of explaining things, and thank you to all who have helped, or might help in the future.
~Jenny
|