Ask Your Question
1

If , else, case?

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

anonymous user

Anonymous

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

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-16 02:58:19 +0100

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-16 03:02:03 +0100 )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 +0100 )edit
1

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

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-16 00:24:08 +0100

Seen: 15,261 times

Last updated: Sep 16 '16