Created
December 12, 2011 15:09
-
-
Save dketov/1467724 to your computer and use it in GitHub Desktop.
Ветвления
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Базовый синтаксис | |
""" | |
x = int(raw_input("Please enter an integer: ")) | |
if x < 0: | |
x = 0 | |
print 'Negative changed to zero' | |
elif x == 0: | |
print 'Zero' | |
elif x == 1: | |
print 'Single' | |
else: | |
print 'More' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Составное условие | |
""" | |
number = 1 | |
if number <= 10 and number >= 1: | |
print 'Great!' | |
else: | |
print 'Wrong!' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Стандартный селектор | |
""" | |
choice = 'ham' | |
print {'spam': 1.25, # a dictionary-based 'switch' | |
'ham': 1.99, # use has_key() or get() for default | |
'eggs': 0.99, | |
'bacon': 1.10}[choice] | |
if choice == 'spam': | |
print 1.25 | |
elif choice == 'ham': | |
print 1.99 | |
elif choice == 'eggs': | |
print 0.99 | |
elif choice == 'bacon': | |
print 1.10 | |
else: | |
print 'Bad choice' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Вложеные условия | |
""" | |
x = 1 | |
if x: | |
y = 2 | |
if y: | |
print 'block2' | |
print 'block1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment