Home python python. How to complete the program when executing the IF condition (text...

python. How to complete the program when executing the IF condition (text quest without using cycles)

Author

Date

Category

There is a task Write a text quest. Write Using only if, elife, else. For example, in the plot, the player chooses one of two actions. If he chose if, the game continues, and if the second condition, the program should display the end of the game and all, i.e. Next, it does not continue and no messages no longer. How to do it with cycles I know. But I use only conditional operators – no. Is there any similarity Break?


Answer 1, Authority 100%

maybe it will not be comfortable, but try using the flag, for example

go = o #GameOver
IF Go! = 1 and someelse:
  SomeCode.
ELIF Go! = 1 and someelse: # In this condition, the player lost
  SomeCode.
  go = 1.
  Print ('Hamper')
ELIF GO! = 1 AND SOMEELSE:
  SomeCode.
ELSE:
  SomeCode.

Please explain to me how to check out the code in the comments)


Answer 2

You can complete the process of executing your quest when it is necessary with sys.exit ()

import sys
sys.exit ()

You can also give a comment comment from the program

import sys
sys.exit ("You Dead")

but

This action will complete the execution of the script at all

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions