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

>
> First number is: > >

> Second number is: > >

> >

> > 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 specification so the frames will be arranged as follows: > > +---+---------+ > | | top | > | l +---------+ > | e | | > | f | bottom | > | t | | > | | | > +---+---------+ You need to specify division into two COLUMNS first, and then subdivide the second column into two ROWS. In what follows, the leftmost column is 123 pixels wide, and the upper-right row is 99 pixels deep. > 7. Write html for a table for the following. Rows are delimited ..., > cells (columns) within a row are delimited with ... > > col1 col2 col3 > Tues Wed Thurs > 3 15 now it's time for html > one last row
col1 col2 col3
Tues Wed Thurs
3 15 now it's time for html
cone last row
> 8. In the code in AE on page 144, there are two boldfaced xsl:for-each statements. > What are they for? Why would xsl need a loop statement, when html does not. > (if you want to say something repeatedly in html, you just repeat the html; > there's no loop construction to do it for you.) XSL defines how to convert xml to html. If the xml has repeating tagged sections, eg First ... Second ... Third ... then the XSL cannot simply handle each in turn because the XSL document has no way of knowing how many repetitions may come. Instead, XSL has loops to indicate that the ... sections are to be repeated in html as many times as they occur in the xml. > 9. What is the significance of how IP addresses are assigned? They are assigned administratively, so that all machines under a common administration (within a given organization) will start with the same network portion of the address. > 10. How does TCP implement reliable transmission, given that the underlying networks > are inherently unreliable? It uses timeouts to detect lost packets, and retransmission to replace them. ==================================================== Python cheat sheet: Loop to print 100 numbers: for i in range(1,101): print i Loop to print a list LIS: for x in LIS: print x Collatz function illustrating while and if: def collatz(n): count = 0 while n != 1: count = count + 1 if n % 2 == 0: n = n/2 else: n = 3*n+1 return count Basic cgi stuff: form = cgi.FieldStorage() n1 = form.getfirst("num1") # get string contents of form field with NAME="num1" n1 = form.getfirst("num1", "100") # 100 is the "default" value, optional num1 = int(n1) # convert a string to an int b1 = form.getlist("button") # get a list of form items with the same name HTML cheat sheet ... ... Headings:

,

,...

bold,italic paragraph

horizontal rule:


"bulleted" list:
  • first
  • second
  • third
Table: # one row with 3 cols # more rows can be repeated as needed
first second third
Frames: Now define as many frames as columns (or rows) were defined above,with: Frames can be new frameset subdivisions instead Forms: just one per html
# text box # checkbox # radio button; # submit button at end