Python Forum

Full Version: Problem witrh else and elif values.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello there i am new into this programming world, and yesteday i was trying to apply the else and elif fonction without any success!
I let you a pic down there to illustrate my problem.

on this link you can find easily the screen shot i made for another trade : http://www.developpez.net/forums/d160496...me-python/

Anolibal.
Bon jour!
I don't know what exactly is the matter with your code, but I tried this and it worked:


a = 150

if (a>5):
   print("bigger")
elif (a < 5):
   print("smaller")
Next time just paste code and error message here, code being within code tags ;)
Also, you don't need the parenthesis in your 'if' and 'elif' statements:

a = 150

if a > 100:
    print('a is bigger')
elif a < 100:
    print('a is smaller')
First of all thanks for your answeres guys !
But even if('i copy paste') you code it still doesn't work ! :( :(
When i type elif or else python reconyze the function but when i type enter
the red message appears agin and again :O That stuff is weird :D
SOS !
Ano

Oh dam yes i found the answere !
For those who are interested :
after the command IF i say print something,
and at this moment i press enter, and then the tiping line goes down.

at this moment i want to type elif but it doesn't work and if i press enter again : >>> will appear again which means that python wait for a new command.
So the thing to do is just to press left arrow once to align the IF , ELIF, and ELSE command so that python understand that THESE are answeres to the IF.

ANOLIBAL
You're trying to use if/elif interactively.  Which means you need to enter both before the next prompt (">>>").
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> if "spam" == "eggs":
...   print("I doubt it.")
... elif "spam" in ["spam", "spam", "spam", "baked beans", "spam"]:
...   print("More likely.")
...
More likely.
>>>
as nilamo is describing, you ended the conditional structure before you intended to. place test code in a small file. make it test only one thing. then run it instead of using the interactive mode. long code is hard to work with in interactive because you probably have to type it again a few times. then it is easier to edit the file and run it again.
[attachment=455]
You hit two times enter, then this block was closed.
In the next lines you tried to continue with your
elif statement, but block was already closed.

If you use the repl (interactive shell), two times ENTER finishes the block.
Just hit only one time enter for the next line.
if you see "..." it is taking more input for the block. if you see ">>>" you are starting a block.

maybe i need to start a course "Introduction to Python Language Interactive Mode 101" for the Freshmen to get them started.