Ask Your Question
1

If , else, case?

asked 2016-09-15 17:24:08 -0500

anonymous user

Anonymous

updated 2016-09-15 17:29:50 -0500

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

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-09-15 19:58:19 -0500

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

Comments

Haha, we nearly had the same answer!

kcrisman gravatar imagekcrisman ( 2016-09-15 20:02:03 -0500 )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-15 20:05:19 -0500 )edit
1

answered 2016-09-15 19:53:22 -0500

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

Stats

Asked: 2016-09-15 17:24:08 -0500

Seen: 273 times

Last updated: Sep 15 '16