Skip to content

Commit 7a60bca

Browse files
committed
Initial commit
0 parents  commit 7a60bca

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Printing to the Console
2+
3+
# Instructions
4+
5+
Write a program in main.py that prints the some notes from the previous lesson using what you have learnt about the Python print function.
6+
7+
**Warning:** The output in your program should match the example output shown below exactly, character for character, even spaces and symbols should be identical, otherwise the tests won't pass.
8+
9+
# Example Output
10+
11+
After you have written your code, you should run your program and it should print the following:
12+
13+
```
14+
Day 1 - Python Print Function
15+
```
16+
17+
```
18+
The function is declared like this:
19+
```
20+
21+
```
22+
print('what to print')
23+
```
24+
25+
e.g. When you hit **run**, this is what should happen:
26+
![](https://cdn.fs.teachablecdn.com/q89uzhvRTf6CZHLtxLm6)
27+
28+
# Test Your Code
29+
30+
Before checking the solution, try copy-pasting your code into this repl:
31+
32+
[https://repl.it/@appbrewery/day-1-1-test-your-code]([https://repl.it/@appbrewery/day-1-1-test-your-code])
33+
34+
This repl includes my testing code that will check if your code meets this assignment's objectives.
35+
36+
37+
# Solution
38+
39+
[https://repl.it/@appbrewery/day-1-1-solution](https://repl.it/@appbrewery/day-1-1-solution)
365 Bytes
Binary file not shown.

main.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#First *fork* your copy. Then copy-paste your code below this line 👇
2+
#Finally click "Run" to execute the tests
3+
print("Day 1 - Python Print Function")
4+
print("The function is declared like this:")
5+
print("print('what to print')")
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
#Copy Paste your code above this line 👆
34+
# 🚨 Do NOT modify the code below this line 👇
35+
with open("testing_copy.py", "w") as file:
36+
file.write("def test_func():\n")
37+
with open("main.py", "r") as original:
38+
f2 = original.readlines()[0:30]
39+
for x in f2:
40+
file.write(" " + x)
41+
42+
import testing_copy
43+
import unittest
44+
from unittest.mock import patch
45+
from io import StringIO
46+
import os
47+
48+
class MyTest(unittest.TestCase):
49+
def test_1(self):
50+
with patch('sys.stdout', new = StringIO()) as fake_out:
51+
testing_copy.test_func()
52+
expected_print = "Day 1 - Python Print Function\nThe function is declared like this:\nprint('what to print')\n"
53+
self.assertEqual(fake_out.getvalue(), expected_print)
54+
55+
print("\n\n")
56+
print('Checking if what you printed matches the target output *exactly*...')
57+
print('Running some tests on your code:')
58+
print(".\n.\n.\n.")
59+
unittest.main(verbosity=1, exit=False)
60+
61+
os.remove("testing_copy.py")
62+
63+

0 commit comments

Comments
 (0)