0% found this document useful (0 votes)
113 views

About Control Statements in Python

Source code of Functions to reach a knowledge on how Control Statements works in Python language. Is a part of python_koans methodology.

Uploaded by

tuxracersv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

About Control Statements in Python

Source code of Functions to reach a knowledge on how Control Statements works in Python language. Is a part of python_koans methodology.

Uploaded by

tuxracersv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#!

/usr/bin/env python
# -*- coding: utf-8 -*from runner.koan import *
class AboutControlStatements(Koan):
def test_if_then_else_statements(self):
if True:
result = 'true value'
else:
result = 'false value'
self.assertEqual(__, result)
def test_if_then_statements(self):
result = 'default value'
if True:
result = 'true value'
self.assertEqual(__, result)
def test_if_then_elif_else_statements(self):
if False:
result = 'first value'
elif True:
result = 'true value'
else:
result = 'default value'
self.assertEqual(__, result)
def test_while_statement(self):
i = 1
result = 1
while i <= 10:
result = result * i
i += 1
self.assertEqual(__, result)
def test_break_statement(self):
i = 1
result = 1
while True:
if i > 10: break
result = result * i
i += 1
self.assertEqual(__, result)
def test_continue_statement(self):
i = 0
result = []
while i < 10:
i += 1
if (i % 2) == 0: continue
result.append(i)
self.assertEqual(__, result)
def test_for_statement(self):
phrase = ["fish", "and", "chips"]
result = []
for item in phrase:

result.append(item.upper())
self.assertEqual([__, __, __], result)
def test_for_statement_with_tuples(self):
round_table = [
("Lancelot", "Blue"),
("Galahad", "I don't know!"),
("Robin", "Blue! I mean Green!"),
("Arthur", "Is that an African Swallow or Amazonian Swallow?")
]
result = []
for knight, answer in round_table:
result.append("Contestant: '" + knight + \
"' Answer: '" + answer + "'")
text = __
self.assertMatch(text, result[2])
self.assertNoMatch(text, result[0])
self.assertNoMatch(text, result[1])
self.assertNoMatch(text, result[3])

You might also like