Multiple choice questions

Feb 2, 2013 • Aleksandra Pawlik

I got myself quite confused with these… I tested them so they should be fine (I hope!).

Q1
Which of the following Makefile rules ensures that publication.pdf will be always built (i.e. the commands in the rule will always run)?

A) publication.pdf: publication.pdf
pdflatex publication.tex
B) publication.pdf: publication.tex
pdflatex publication.tex
touch publication.pdf
C) publication.pdf: publication.tex
pdflatex publication.tex
D) publication.pdf:
pdflatex publication.tex
A) Makefile will complain --- it's a cyclic dependency. The student may select this forgetting about this Makefile property.
B) This will only run if the source, publication.tex gets updated. The student may select this being mislead by 'touch publication.pdf' (thinking that the target file timestamp should be updated).
C) Again, this will only run if the source, publication.text is updated. The student may select this due to the same reasons as in B.
D) Correct.

Q2
If, in Python, b=”LosAngeles”, then which of the following will give us ‘Los Angeles’ in the output?
A) c = b[:3] + “  “ + b[3:]
return c
B) c = b[:3] + “  “ + b[3:1000]
print c
C) c = b[1:3] + “  “ + b[4:10]
print c
D) c = b[0:0] + b[1:1] + b[2:2] + “  “ + b[3:10]
print c

A) The concatenation of strings will work. But ‘return c’ will give an error. The student may select this if he/she confuses ‘return’ with ‘print’.
B) Correct.
C) This will return ‘os ngeles’. The student may select this if he/she thinks that indexing in Python starts from 1.
D) This will return ‘  Angeles’. The student may select this if he/she confuses b[0:0] with b[0] (so doesn’t understand slicing).