This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by gromiczek
about 11 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.

points
Submitted by raberaucht12
about 11 years

1 comments

thehopp about 11 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.)

points
Submitted by Keevin
about 11 years

1 comments

Vincent Iannone almost 11 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’

points
almost 11 years

1 comments

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)

points
over 10 years