The big if


#1

a=int(input("Please enter a number = "))
x=10
y=20
if (a>=10 and a<=20):
print(“Your value is in range”)
elif (a<10):
print(“Your value is under 10”)
else :
print(“Your value is above the range”)

THIS PROGRAM RUNS SMOOTHLY IN MY PYTHON IDLE BUT THE COMPILER IN THE PROGRAM SHOWS

Traceback (most recent call last):
File “python”, line 6, in
NameError: name ‘a’ is not defined

PLEASE HELP ME WITH THIS


#2

could point out
where did you define the VARIABLE a ???


#3

inside the function def the_flying_circus():


#4

I do not see this def flying_circus of yours…
and please =select-your-code= and then click on the </> button
so the indentation you are using is visible …


#5

He defines it in the top of the code he has posted:

a=int(input("Please enter a number = "))

but he has made a typo as I have marked with bold. In Python, you don’t type “input(“example”)”, when you prompt a user for input, you type “raw_input(“example”)”


#6

@vicedivic
@designcoder11780

nice to know
https://stackoverflow.com/questions/3800846/differences-between-input-and-raw-input


#7

don’t understand the difference between raw_input and input


#8

I’m using python 3.6 it uses input instead of raw_input


#9

Then it must be your indentation that is wrong, you see:

Everything is on the same column, but where you have your if/elif/else statement, there should be indentation


#10

your if else statement should be inside of def the_flying_circus(): with proper indentation.

if statement should be start at same level below y


#11

“”“The code below, that I tested works perfectly fine for me, basicly what I did is set 3 variables and just do one that will be true, and the rest i did false, with boolenas. I also didnt know that you have to use return for it to work, but here is the code if anybody needs it!”""

Make sure that the_flying_circus() returns True

a = 100
b = 100
c = 200

def the_flying_circus():

if a == b:
print 'Gut gemacht!'
return True

elif a <= b or a < b:
print 'Ok’
return False

else :
print 'Sorry’
return False


#12

Dont forget to indent the print and return, they need to be on the same indent (4 times space or tab)


#13

Have a look at the version you are having the problem in…
https://www.codecademy.com/en/forum_questions/54bc9a5fd3292f9b4a005506
and
do a google search
python {the-version-with-error} vs {the-version-with-no-error} site:stackoverflow.com


#14

python 2.x uses raw_input
python 3.x uses input


#15

Hi all! I tried a lot of different ways. Can anybody give me an example code so that i can correct my codes?


#16

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