2nd assignment

Write the code for a simple book (pdf).

Send me this code (.py or .ipynb) until 14.12. together with the resulting PDF. (If you’ll send .py via mail, you have to .zip it.)

No worries, you don’t have to spend a lot of time with it, it’s just an exercise for you to write some code.

To limit you (and your amount of work), the code is constrained to the elements we’ve learned so far. (So you can’t use anything of Python or FPDF that we haven’t used already.)

# variables of type int, float, str

# overriding variables

# simple mathematical operations
+
-
/
*

# casting of data types
int()
float()
str()

# lists
# like
advent_calendar = ['apple', 'beer', 'cherry', 'date']

# for loops 
# like
for i in range(2, 11):
    print(i)

# or
for item in advent_calendar:
    print(item)
    
# if ... elif ... else

# booleans like 
13 % 2 == 0

# while-loop like
a = 0
while a < 10:
    print(a)
    a += 1
    
# string methods like
split()
.join()

# string formatting 

# writing/ reading files like
with open('my_text', 'r') as f:
    txt = f.readlines()

And of course the FPDF library.

FPDF() # the object itself

# the following methods
.add_font()
.add_page()
.ln()
.multi_cell()
.page_no() # returns the page number (like txt = pdf.page_no())
.set_fill_color()
.set_font()
.set_font_size()
.set_margins()
.set_text_color()
.set_x
.set_xy
.set_y
.output()

Help pages for FPDF:

add_font

add_page

ln

multi_cell

set_fill_color

set_font

set_font_size

set_margins

set_x

set_x_y

set_y

set_text_color

output