Ask Your Question

If , else, case?

asked 2016-09-16 00:24:08 +0200

anonymous user


updated 2016-09-16 00:29:50 +0200


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.'
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-09-16 02:58:19 +0200

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:

edit flag offensive delete link more


Haha, we nearly had the same answer!

kcrisman gravatar imagekcrisman ( 2016-09-16 03:02:03 +0200 )edit

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 ( 2016-09-16 03:05:19 +0200 )edit

answered 2016-09-16 02:53:22 +0200

kcrisman gravatar image

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

edit flag offensive delete link more

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


Asked: 2016-09-16 00:24:08 +0200

Seen: 13,338 times

Last updated: Sep 16 '16