Profile image of gromiczek
Submitted by gromiczek
over 12 years

1.4 How to make "else:" do nothing?

I’m working on A Day at the Supermarket 1.4 and curiously, I can make the “if” statement work just fine, but the trouble I’m having is how to make the “else:” statement do nothing. I tried various things such as:

else: return “nothing.”

else: return 0

Thoughts?

Answer 50b0e86b1fd37a027c0000db

10 votes

Permalink

Just leave the ‘else’ part out.

Profile image of raberaucht12
Submitted by raberaucht12
over 12 years

1 comments

Profile image of thehopp
Submitted by thehopp
over 12 years

I agree it’s 100% unecessary

Answer 50b52dfaba18aef087000063

1 vote

Permalink

For the line after “else:” use the “pass” no-op python keyword

It looks a little bit like this


else:
    pass

(The indentation gets lost when I submit the edit. The preview looks fine.)

Profile image of KevinN.Leeds
Submitted by KevinN.Leeds
over 12 years

1 comments

Profile image of vinnieiannone
Submitted by vinnieiannone
over 12 years

If you press control+K you can leave a code sample, which you can also find in the visual GUI which looks like this -> {}

Answer 50d9ace8f9a480e85500445e

0 votes

Permalink

A = [0,1,2,3,4,5,6,7,8,9,10,11,12,13]

for num in A: if (num%2==0): print num else: ‘odd’

Profile image of arcAce26477
Submitted by arcAce26477
over 12 years

1 comments

Profile image of arcAce26477
Submitted by arcAce26477
over 12 years

control + K still does not help with indentation!!!

Answer 51c2e5548c1ccc8bbd007e20

0 votes

Permalink

just do something that doesn’t affect anything, like x = x (make sure this is a variable in your script)

Profile image of loizos1997yahoo.com.au
about 12 years