summaryrefslogtreecommitdiff
path: root/getting_started_with_functions/script.rst
diff options
context:
space:
mode:
authorJovina2011-07-08 17:06:42 +0530
committerJovina2011-07-08 17:06:42 +0530
commit22aae6a95dd1b330536057b051434efb2a7fbc5d (patch)
treea56738ee255ed01659c081bbd9ac2c5c993c0fb3 /getting_started_with_functions/script.rst
parentdd1699be35284e56d2972e71608ed69a3e8731ab (diff)
downloadst-scripts-22aae6a95dd1b330536057b051434efb2a7fbc5d.tar.gz
st-scripts-22aae6a95dd1b330536057b051434efb2a7fbc5d.tar.bz2
st-scripts-22aae6a95dd1b330536057b051434efb2a7fbc5d.zip
Minor changes to script of 'getting started with functions'.
Diffstat (limited to 'getting_started_with_functions/script.rst')
-rw-r--r--getting_started_with_functions/script.rst58
1 files changed, 29 insertions, 29 deletions
diff --git a/getting_started_with_functions/script.rst b/getting_started_with_functions/script.rst
index 4288224..41ef94c 100644
--- a/getting_started_with_functions/script.rst
+++ b/getting_started_with_functions/script.rst
@@ -375,13 +375,13 @@ Now we have done enough coding, let us do some code reading exercise,
Pause here and try to figure out what the function ``what`` does.
-.. def what( n ):
-.. if n < 0: n = -n
-.. while n > 0:
-.. if n % 2 == 1:
-.. return False
-.. n /= 10
-.. return True
+ def what( n ):
+ if n < 0: n = -n
+ while n > 0:
+ if n % 2 == 1:
+ return False
+ n /= 10
+ return True
{{{continue from paused state}}}
It will return true if ``n % 2`` is not equal to 1 and will return false, otherwise.
@@ -392,15 +392,15 @@ It will return true if ``n % 2`` is not equal to 1 and will return false, otherw
{{{ switch to next slide, even_digits }}}
-.. def even_digits( n ):
-.. """returns True if all the digits in the number n are even,
-.. returns False if all the digits in the number n are not even"""
-.. if n < 0: n = -n
-.. while n > 0:
-.. if n % 2 == 1:
-.. return False
-.. n /= 10
-.. return True
+ def even_digits( n ):
+ """returns True if all the digits in the number n are even,
+ returns False if all the digits in the number n are not even"""
+ if n < 0: n = -n
+ while n > 0:
+ if n % 2 == 1:
+ return False
+ n /= 10
+ return True
.. R32
@@ -417,11 +417,11 @@ Now one more code reading exercise,
Pause here and try to figure out what the function ``what`` does.
-.. def what( n ):
-.. i = 1
-.. while i * i < n:
-.. i += 1
-.. return i * i == n, i
+ def what( n ):
+ i = 1
+ while i * i < n:
+ i += 1
+ return i * i == n, i
{{{continue from paused state}}}
The function returns two values. One it returns the result of the while statement
@@ -431,14 +431,14 @@ whether true of false, and second it prints the value that `ii`` currently holds
{{{ switch to next slide, is_perfect_square }}}
-.. def is_perfect_square( n ):
-.. """returns True and square root of n, if n is a perfect square,
-.. otherwise returns False and the square root of the
-.. next perfect square"""
-.. i = 1
-.. while i * i < n:
-.. i += 1
-.. return i * i == n, i
+ def is_perfect_square( n ):
+ """returns True and square root of n, if n is a perfect square,
+ otherwise returns False and the square root of the
+ next perfect square"""
+ i = 1
+ while i * i < n:
+ i += 1
+ return i * i == n, i
.. R34