How to solve this problen? I get stucked


#1

Hi, master,
I suffer one question when I am learning Python during codecademy.

The response is
_ops, try again. An exception was raised while running your code, see the console window for the error message.
Traceback (most recent call last):
_ File "python", line 11, in _
NameError: name 'a' is not defined

How could I solve it?

Code:

Make sure that the_flying_circus() returns True

def the_flying_circus(a):
if a>8: # Start coding here!
# Don't forget to indent
return 1
elif a<8:
# Keep going here.
return -1
else:
return 0
print the_flying_circus(a)


#2

NameError: name 'a' is not defined

where the Error come from

print the_flying_circus(a) # this line

what is a ? a is number ? or string?

this is the first step . now think what should you pass as argument?
you are checking

if a>8:


#3

thanks for your reply
How could I make the a as a statement?


#4

Make sure that the_flying_circus() returns True

def the_flying_circus(a):
if 'a'>8: # Start coding here!
# Don't forget to indent
return 1
elif 'a'<8:
# Keep going here.
return -1
else:
return 0
print the_flying_circus(7)

Oops, try again. the_flying_circus should not take any arguments.


#5

your code is fine! dont worry about it.
but here you are not told to do so.
so dont take any parameter and a argument too.

def the_flying_circus(): # without any parameter

and

the_flying_circus() # calling the function without any argument


#6

Dear friend, thanks for your patience.
My english is poor.
I made change as your instruction, but the code still did not run well.

Oops, try again. the_flying_circus() should return True, instead it returned: 1

Make sure that the_flying_circus() returns True

def the_flying_circus():
if 'a'>8: # Start coding here!
# Don't forget to indent
return 1
elif 'a'<8:
# Keep going here.
return -1
else:
return 0
print the_flying_circus()


#7

read the instruction number 4

Finally, the_flying_circus() must return True when evaluated.

write return True instead of return 1

always do what instruction told to do.


#8

Thanks you sir.
Now it run well.
But I can not understand, where did the True come from....
To be honest, the "a" here, is worthless, because the answer of these code will always be true.

Thank you so much friend. Your kindly heart makes me warm.

Make sure that the_flying_circus() returns True

def the_flying_circus():
if 'a'>8: # Start coding here!
# Don't forget to indent
return True
elif 'a'<8:
# Keep going here.
return -1
else:
return 0
print the_flying_circus()


#9

True is a boolean value so you can say you are returning boolean value nothing else.

a is really worthless and always will be if you are cheking like 'a' (as a string)

if 'a'>8:

with quotes a is a string now.if you pass an arguments it'll remain a string.dont do like this.

now here in this lesson just focus on how to write if ,elif and else . how to indent... etc

though you passed the lesson but what i see you didn't complete instrunction(number 2)


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.