Complete the below Python fragment so that it computes and displays the length of the longest line in the text file.
essay = open('words.txt')
Assuming scores.txt is a file of integers, with one integer on each line, complete the below Python fragment so that it computes and displays the average of the numbers in the file.
data = open('scores.txt')
What is displayed by the following Python fragment?
words = 'The quick brown fox jumps over the lazy dog'
map = {}
for word in words.split():
map[len(word)] = word
for k in range(3, 6):
print k, map[k]
Suppose we have a dictionary scores
mapping names (each a string) to test scores (each an integer).
Write a program fragment that displays the name of each student
whose score is 100.
Explain as best you can how the IP address 209.65.57.4 comes to be allocated to ozark.hendrix.edu.
In the context of networking, why do messages typically
include port numbers
rather than simply the computers' IP addresses?
What does a name server do in the Domain Name System (DNS)?
max_length = 0
for line in essay:
if len(line) > max_length:
max_length = len(line)
print max_length
line_count = 0
total = 0
for line in data:
line_count += 1
total += float(line.rstrip())
print 'Average is', total / line_count
3 dog 4 lazy 5 jumps
for name in scores:
if scores[name] == 100:
print name
An international agency called ICANN allocates blocks of
addresses to Internet service providers, such as AT&T.
[Actually, ICANN gives blocks to regional Internet
registries,
of which there is essentially one for each
continent, and these registries allocate within these blocks to
ISPs.] They might have given AT&T all addresses that start
with 209.65, for example. AT&T
then divvies this range of addresses among their customers, such as
Hendrix College. Thus, Hendrix College ends up receiving all
addresses whose first 22 bits match with 209.65.56.0 —
that is, 209.65.56.0 through 209.65.59.255. Hendrix
splits its address space some, and they gave the computer science
network all addresses whose first 26 bits match with
209.65.57.0. Then the network administrator decided to
assign one of those — 209.65.57.4 — to
its computer named ozark.
A port number, allocated uniquely on the computer for each program running, allows a sender to identify the particular program on the destination computer that should receive the message.
A name server receives requests including the name of a computer (such as ozark.hendrix.edu) and responds with the computer's IP address (such as 209.65.57.4).