2015-10-11 3 views
0
elif schoice2 == 2: 
    print "You run away from the bear about as fast as Usian Bolt, even though you have no clue who that is since it's the year 1112, but you decide not to dwell on who or what a 'Usian Bolt' is. The bear gives chase, then ultimitely crashes down on you, giving you a fast death." 
    print "YOU ARE DEAD, TRY AGAIN!" 

Так что я хочу знать, есть ли команда, которая полностью прекращает выполнение скрипта.Создание Failstate в Python

+1

'sys.exit (0)'? Ваш вопрос нечеткий ... ... –

+0

['' 'raise'''] (https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement) Исключение. ? – wwii

+0

Вы хотите использовать ['raise'] (https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement), так как wwii сказал, чтобы вызвать ошибку? или использовать ['sys.exit()'] (https://docs.python.org/3.5/library/sys.html#sys.exit), так как g.d.d.c сказал, чтобы выйти из программы? –

ответ

0

Для выхода из сценария в коде вы должны сделать это:

sys.exit() функция выхода из программы, и выдает сообщение об ошибке. Это функция, выполняемая по желанию.

import sys 
#do some stuff 
elif schoice2 == 2: 
    print "You run away from the bear about as fast as Usian Bolt, even though you have no clue who that is since it's the year 1112, but you decide not to dwell on who or what a 'Usian Bolt' is. The bear gives chase, then ultimitely crashes down on you, giving you a fast death." 
    print "YOU ARE DEAD, TRY AGAIN!" 
    sys.exit() 

EDIT:

quit() функция не даст сообщение об ошибке, и будет только закончить программу.

Новый код будет выглядеть следующим образом:

import sys 
#do some stuff 
elif schoice2 == 2: 
    print "You run away from the bear about as fast as Usian Bolt, even though you have no clue who that is since it's the year 1112, but you decide not to dwell on who or what a 'Usian Bolt' is. The bear gives chase, then ultimitely crashes down on you, giving you a fast death." 
    print "YOU ARE DEAD, TRY AGAIN!" 
    quit()