diff --git a/challenges/1.1.Print/lesson.md b/challenges/1.1.Print/lesson.md index e69de29..08f62bf 100644 --- a/challenges/1.1.Print/lesson.md +++ b/challenges/1.1.Print/lesson.md @@ -0,0 +1,34 @@ +## Print +- http://www.python-course.eu/python3_print.php +The print() function is used to present the output of a program. +``` +>>> print(“Hello World”) +Hello World +``` +It can have several parameters. +``` +>>> print(‘Hello’, 12, ‘98’) +Hello 12 98 +``` +The arguments of the print function: +sep=’’ +Sep is a separator, it is used to divide parameters. +``` +>>> print(‘Hello’, “World’, sep=’-‘) +Hello-World +``` +We can assign an string to the keyword parameter "end". This string will be used for ending the output of the values of a print call. +end=’’ +``` +>>> print(‘Hello’, ‘World’, end=’!’) +Hello World? +``` +By redefining the keyword parameter "file" we can send the output into a different stream file. +file=’’ +``` +>>> fh = open("data.txt","w") +>> print("no", file=fh) +>>> fh.close() +``` +**_Instructions:_** +**Put your name and sname to appropriate places, change '*' to parameters of separator '_' and in the end of the line '!'.** diff --git a/challenges/1.1.Print/lesson_tests.py b/challenges/1.1.Print/lesson_tests.py index e69de29..37bbad0 100644 --- a/challenges/1.1.Print/lesson_tests.py +++ b/challenges/1.1.Print/lesson_tests.py @@ -0,0 +1,10 @@ +import unittest + + +class PrintTests(unittest.TestCase): + def test_main(self): + f = open('main.py') + lines = str(f.readlines()) + f.close() + self.assertRegex(lines, "sep='_'", msg="_ mising") + self.assertRegex(lines, "end='!'", msg="! mising") \ No newline at end of file diff --git a/challenges/1.1.Print/main.py b/challenges/1.1.Print/main.py index e69de29..a30ae45 100644 --- a/challenges/1.1.Print/main.py +++ b/challenges/1.1.Print/main.py @@ -0,0 +1 @@ +print('firstname', 'sname', sep='*', end='*') #change this line diff --git a/challenges/1.2.Escape_Characters/lesson.md b/challenges/1.2.Escape_Characters/lesson.md index e69de29..cb51b23 100644 --- a/challenges/1.2.Escape_Characters/lesson.md +++ b/challenges/1.2.Escape_Characters/lesson.md @@ -0,0 +1,20 @@ +## Escape Character +The escape character is "\\" and this character is invoked an alternative interpretation in a character sequence. +- https://docs.python.org/2.0/ref/strings.html +``` +>>> print('\\') +\ +>>> print('\'') +' +>>> print('Helllo\nWorld') +Hello +World +``` +We can use escape character to print hex value Unicode character. +``` +>>> print('\uxxxx') +Л +``` + +**_Instructions:_** +**Use escape character "new line" in the string_escape** \ No newline at end of file diff --git a/challenges/1.2.Escape_Characters/lesson_tests.py b/challenges/1.2.Escape_Characters/lesson_tests.py index e69de29..7ab0e97 100644 --- a/challenges/1.2.Escape_Characters/lesson_tests.py +++ b/challenges/1.2.Escape_Characters/lesson_tests.py @@ -0,0 +1,7 @@ +import unittest +from main import * + + +class EscapeTests(unittest.TestCase): + def test_main(self): + self.assertRegex(repr(string_escape), r'\\n', msg='the string must contain "new line"') \ No newline at end of file diff --git a/challenges/1.2.Escape_Characters/main.py b/challenges/1.2.Escape_Characters/main.py index e69de29..e953a27 100644 --- a/challenges/1.2.Escape_Characters/main.py +++ b/challenges/1.2.Escape_Characters/main.py @@ -0,0 +1,4 @@ +string_escape = 'Hello, this is escape string' # change this line + +# change the string_escape, the string must contain "new line" +print(string_escape) \ No newline at end of file diff --git a/challenges/6.1.Conditionals/lesson.md b/challenges/6.1.Conditionals/lesson.md new file mode 100644 index 0000000..198a310 --- /dev/null +++ b/challenges/6.1.Conditionals/lesson.md @@ -0,0 +1,30 @@ +## if elif else + +- https://docs.python.org/3/tutorial/controlflow.html + +Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome. You need to determine which action to take and which statements to execute if outcome is TRUE or FALSE otherwise. In Python zero and null is assumed as FALSE value. +``` +if value == 'some': + print('yes') +``` +An else statement contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value. +``` +if value == 'some': + print('yes') +else: + print('no') +``` + +The elif statement allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE. + +``` +if value == 'some': + print('yes') +elif value = 'value': + print('maybe') +else: + print('no') +``` + +**_Instructions_** +**Modify the value, so that program must print 'yes'.** diff --git a/challenges/6.1.Conditionals/lesson_settings.py b/challenges/6.1.Conditionals/lesson_settings.py new file mode 100644 index 0000000..a901770 --- /dev/null +++ b/challenges/6.1.Conditionals/lesson_settings.py @@ -0,0 +1,7 @@ +{ + "lesson_title": "Conditionals", + "chapter_number": 6, + "lesson_number": 1, + "id":"5965e5fd60d67217f0ce232f", + "repl": "" +} diff --git a/challenges/6.1.Conditionals/lesson_tests.py b/challenges/6.1.Conditionals/lesson_tests.py new file mode 100644 index 0000000..6d274d0 --- /dev/null +++ b/challenges/6.1.Conditionals/lesson_tests.py @@ -0,0 +1,7 @@ +import unittest +from main import * + +class ConditionalsTests(unittest.TestCase): + def test_main(self): + self.assertIsInstance(value, str) + self.assertIs(value, 'y', "program must print 'yes'") \ No newline at end of file diff --git a/challenges/6.1.Conditionals/main.py b/challenges/6.1.Conditionals/main.py new file mode 100644 index 0000000..faf0d94 --- /dev/null +++ b/challenges/6.1.Conditionals/main.py @@ -0,0 +1,8 @@ +value = 'some' #modify this line + +if value == 'Y' or value == 'y': + print('yes') +elif value == 'N' or value == 'n': + print('no') +else: + print('error') diff --git a/challenges/7.1.Loops/lesson.md b/challenges/7.1.Loops/lesson.md new file mode 100644 index 0000000..d80d890 --- /dev/null +++ b/challenges/7.1.Loops/lesson.md @@ -0,0 +1,38 @@ +## Loops (While) + +- https://docs.python.org/3/tutorial/controlflow.html + +A loop statement allows to execute a block of code multiple times. Python supplies two type of loops: +* while +* for + +The syntax of a while loop is: + +``` +while condition: + statement +``` + +While loops repeat a target statement as long as a given condition is true. + +``` +count = 0 +while count < 9: + print('Loop iteration: ', count) + count = count + 1 +``` + +Python supports to have an else statement associated with a loop statement. The else statement is executed when the condition becomes false. + +``` +count = 0 +while count < 9: + print('Loop iteration ', count) + count = count + 1 +else: + print('loop end') +``` + +**_Instructions_** +**Modify the count, so that condition and switch_loop must become true.** +**Use else statement, to mark the end of a program and switch switch_end to value true.** diff --git a/challenges/7.1.Loops/lesson_settings.py b/challenges/7.1.Loops/lesson_settings.py new file mode 100644 index 0000000..f6d8ee3 --- /dev/null +++ b/challenges/7.1.Loops/lesson_settings.py @@ -0,0 +1,7 @@ +{ + "lesson_title": "Loops", + "chapter_number": 7, + "lesson_number": 1, + "id":"597e1a1a634a36abfebcda38", + "repl": "" +} diff --git a/challenges/7.1.Loops/lesson_tests.py b/challenges/7.1.Loops/lesson_tests.py new file mode 100644 index 0000000..0a206ab --- /dev/null +++ b/challenges/7.1.Loops/lesson_tests.py @@ -0,0 +1,7 @@ +import unittest +from main import * + +class LoopsTests(unittest.TestCase): + def test_main(self): + self.assertTrue(switch_end) + self.assertTrue(switch_loop) diff --git a/challenges/7.1.Loops/main.py b/challenges/7.1.Loops/main.py new file mode 100644 index 0000000..f0aac5c --- /dev/null +++ b/challenges/7.1.Loops/main.py @@ -0,0 +1,12 @@ +count = 10 # Change this count +switch_loop = False +switch_end = False + +while count < 9: + print('step ', count) + count = count + 1 + switch_loop = True +# use else statements + print('loop end') + switch_end = True; +