Created
December 13, 2011 14:06
-
-
Save dketov/1472235 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 -*- | |
""" | |
Определение функции | |
""" | |
def square(x): | |
'Calculates the square of the number x.' | |
return x*x | |
print square(100) | |
def factorial(n): | |
result = n | |
for i in range(1,n): | |
result *= i | |
return result | |
print factorial(10) | |
def fib(n): # write Fibonacci series up to n | |
"""Print a Fibonacci series up to n.""" | |
a, b = 0, 1 | |
while b < n: | |
print b, | |
a, b = b, a+b | |
# Now call the function we just defined: | |
fib(2000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment