question
Dan Upton
upton at virginia.edu
Thu May 29 18:53:29 EDT 2008
On Thu, May 29, 2008 at 6:41 PM, Gandalf <goldnery at gmail.com> wrote:
> On May 30, 12:14 am, John Henderson <jhenRemoveT... at talk21.com> wrote:
>> Gandalf wrote:
>> > how do i write this code in order for python to understand it
>> > and print me the x variable
>>
>> > x=1
>> > def aaaa():
>> > x++
>> > if x > 1:
>> > print "wrong"
>> > else :
>> > print x
>>
>> > aaaa()
>>
>> Example:
>>
>> x=1
>> def aaaa(x):
>> x += 1
>> if x > 1:
>> return "wrong"
>> else :
>> return x
>>
>> print aaaa(x)
>>
>> John
>
> mmm isn't their any global variable for functions?
If I get what you're asking, you have to tell the function there
exists a global:
IDLE 1.2
>>> x=1
>>> def a():
global x
x+=1
if x > 1:
print x
else:
print "nope"
>>> print x
1
>>> a()
2
>>> print x
2
More information about the Python-list
mailing list