Skip to content
Snippets Groups Projects
Commit c3d19cf0 authored by John Feiner's avatar John Feiner
Browse files

Merge branch 'main' of mode.fh-joanneum.at:secure-code/workshop

parents 1c9bf3a8 a3cbb991
No related branches found
No related tags found
No related merge requests found
__pycache__
*.xlsx
*.csv
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.title = "Umsatz"
data = [
# A B C D
["Apfel", 1.2, 10], # 1
["Birne", 1.4, 15], # 2
["Kirsche", 2.5, 7], # 3
]
for idx, row in enumerate(data, 1):
row.append(f"=B{idx}*C{idx}")
ws.append(row)
ws["D4"] = "=SUM(D1:D3)"
wb.save("umsatz.xlsx")
# with open("data.csv", "w") as f:
# for line in data:
# f.write(f"{line[0]},{line[1]},{line[2]}\n")
openpyxl
#!/usr/bin/env python3
def pretty_output(msg, indent=3):
return f"{' '*indent}{msg}"
# print("Please comment this later, we just test if it works")
# START
#
# Please check now: Did the output look like:
# Hi
# Hi
#
# END
from example import pretty_output
out = pretty_output("Hi", 3)
assert out == " Hi"
out = pretty_output("Hi", indent=5)
assert out == " Hi"
import unittest
from example import pretty_output as pretty_format
class TestPrettyPrintFunctions(unittest.TestCase):
def test_normal_params(self):
should = " Hi"
result = pretty_format("Hi",indent=2)
self.assertEqual(result, should)
def test_edge_case_negative_indent(self):
should = "Hi"
result = pretty_format("Hi",indent=-2)
self.assertEqual(result, should)
if __name__ == "__main__":
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment