Created
December 12, 2011 15:36
-
-
Save dketov/1467905 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 -*- | |
""" | |
Итерация по списку | |
""" | |
words = ['A', 'B', 'C', 'D', 'E'] | |
for word in words: | |
print word |
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 -*- | |
""" | |
Итерация по словарю | |
""" | |
dict = {'x': 1, 'y': 2, 'z': 3} | |
for key in dict: | |
print key, 'corresponds to', dict[key] |
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 -*- | |
""" | |
Использование функции range() | |
""" | |
from math import sqrt | |
for n in range(99, 0, -1): | |
root = sqrt(n) | |
if root == int(root): | |
print n | |
break |
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 -*- | |
""" | |
Подсчёт сложных процентов | |
""" | |
principal = 1000.0 # starting principal | |
rate = .05 # interest rate | |
print "Year %21s" % "Amount on deposit" | |
for year in range( 1, 11 ): | |
amount = principal * ( 1.0 + rate ) ** year | |
print "%4d%21.2f" % ( year, amount ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment