First time here? Check out the FAQ!

Ask Your Question
1

If , else, case?

asked 8 years ago

anonymous user

Anonymous

updated 8 years ago

Hallo!

Is there a function to help me out to test a condition without a 'cascade' of 'else(s)'? Like a "case"? I'm trying hard to find out a solution using the build-in help/manual and could not find a "case" statement. Thank you in advance.

r = randint(1,3)
if r == 1:
        print 'One.'
if r == 2:
        print 'Two.'
if r == 3:
        print 'Three.'
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 8 years ago

tmonteil gravatar image

Sage uses the Python programming language, and there is no case statement in Python, instead it is recommended to use if elif elif ..., see:

Preview: (hide)
link

Comments

Haha, we nearly had the same answer!

kcrisman gravatar imagekcrisman ( 8 years ago )

And i was just about to open a ticket for the chromatic number of the empty graph, when i saw your ticket !!!

tmonteil gravatar imagetmonteil ( 8 years ago )
1

answered 8 years ago

kcrisman gravatar image

This is a Python question ... and, unsurprisingly, it has been asked before, though I don't think on this forum.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 15,952 times

Last updated: Sep 16 '16