Study Guide #2 selected answers (in preparation)
> Sample problems:
>
> 1. Write a python function to multiply all the numbers in a list L:
def mulnums(L):
prod = 1
for x in L:
prod = prod * x
return prod
> 2. Discuss the security risks involved in having your browser run
> programs downloaded remotely from a web page, and discuss how java
> applets and Microsoft activeX each deal with these risks.
THe security problem is that when you run a program on your computer,
you are giving that program access to your entire computer. The program
may have harmful consequences you didn't intend.
Java Applets deal with this by restricting access to the local computer.
(Ordinary java programs don't have this limitation.) An applet cannot
damage or even look at any files on the local computer.
ActiveX deals with this by certifying that the program is from the
stated source. It's then up to the user to decide if they trust
programs from that source.
> 3. Consider the following network, with six hosts A-F and three routers R1, R2, R3.
> Assume each host needs its own entry in each router. Give routing tables for
> the routers.
>
>
> A C E
> | | |
> | | |
> 1 1 1
> R1-2-------------2-R2-4-------------2-R3
> 3 3 3
> | | |
> | | |
> B D F
I should have given interface numbers for the routers; they are included
in the diagram above. The alternative is to specify next hop as a named node;
both forms of the answer are given here:
R1
next_hop next_hop
dest interface node
A 1 A
B 3 B
C 2 R2
D 2 R2
E 2 R2
F 2 R2
R2
next_hop next_hop
dest interface node
A 2 R1
B 2 R1
C 1 C
D 3 D
E 4 R3
F 4 R3
R3
next_hop next_hop
dest interface node
A 2 R2
B 2 R2
C 2 R2
D 2 R2
E 1 E
F 3 F
> 4. Consider the following html form. Write a python cgi program (it doesn't
> have to work, it just has to be plausible) that accesses the two fields
> and prints their sum:
>
>
>
>
> Calculator
>
>
>
Plain text version:
def main():
form = cgi.FieldStorage()
n1 = int(form.getfirst("num1"))
n2 = int(form.getfirst("num2"))
print "Content-type: text/plain\n\n"
print "sum is ", n1+n2
You can also have the first line say
print "Content-type: text/html\n\n"
and then have the second line print the result in html format.
> 5. How would the html above appear on the user's screen?
I'm using ______ to denote where the input box would be:
CALCULATOR
First number is: __________________________
Second number is: __________________________
__Submit__
> 6. Write a