Let us worry about your assignment instead!

We Helped With This Python Programming Homework: Have A Similar One?

More InfoPython Help

Short Assignment Requirements

Accessing the InternetCreate a function in JES that pulls a picture from a URL and creates a thumbnail saved on your local machine. Since this assignment specifies the picture should be saved as a "thumbnail," the full answer should include a function that decreases the image to a thumbnail size (saveThumbnail2). However, if the picture pulled from a URL was a thumbnail originally, your function should just save the image without resizing (saveThumbnail1). Review the program presented in Ch. 13.2 Program 163, "Writing Programs to Generate HTML," of Introduction to Computing and Programming in Python. Zip your Python .py file and submit the.zip file so the code can be validated.

Assignment Description

Individual: Accessing the Internet WEEK 3

Review the program presented in Ch. 13.2 Program 163, "Writing Programs to Generate HTML," of Introduction to Computing and Programming in Python.





HTML itself is not a programming language. HTML can’t specify loops, conditionals, variables, data types, or anything else we’ve learned about specifying process. HTML is used to describe structure, not process.

That said, we can easily write programs to generate HTML. Python’s multiple ways of quoting strings come in really handy here!

image Program 159: Generating a Simple HTML Page

def makePage():


  file.write("""<!DOCTYPE html>



<head> <title>The Simplest Possible Web Page</title>



<h3>A Simple Heading</h3>

<p>Some simple text.</p>




This works but it’s really boring. Why would you write a program to write what you can do with a text editor? You write programs for replicability, communicating process, and tailoring.

One of the most reasons that Web pages are generated are for catalogs. Web sites like Amazon and E-Bay don’t really have individual Web pages for each and every product. Rather they have some templates (essentially, functions that generate HTML) that they use to specify a few parameters and then generate a Web page.

Our first example is a function that takes as input a product name, an image file for the product, and a price. It generates a page that looks like Figure 13.7.

We call this function like this:

>>> makeCatalog("Seahorses","seahorses.jpg",32.75)

image Program 160: A Catalog Page Generator

def makeCatalog(product, image, price):


  body = """<!DOCTYPE html>



<title>Catalog Page for:"""+ product+'''</title>



<h3>'''+product+""" is the greatest!</h3>

<p>You are so lucky to have found this page!

You have the opportunity to buy """+product+"""

for the low, low price of $"""+str(price)+'''.

Just take a look at this beauty!

<img src="'''+image+'''" height = 100></p>

<p>Get one today!</p>







A sample catalog product page.

How It Works

Our function makeCatalog takes in a product, image, and price. We open a writable text file in the media folder named “catalog.html.” We then make up a really big string named body.

·         We use triple quotes so that we can put in returns within the string. We sometimes use triple double-quotes and sometimes triple single-quotes in order to make it easier to understand the quote marks inside the HTML.

·         We escape the string to insert the product name into the title Catalog Page for: (in our case) Seahorses. Clearly, the program expects a singular product, not a plural. The sentences are grammatically incorrect with a plural word as input. Computers will do just what we tell them to do, even if it’s wrong.

·         We then expound upon the glories of this product, including the low, low price—which is a floating-point number, so we have to convert it into a string with str(price).

·         We again escape the string to insert the actual filename for the image.

After formatting the whole body string, we write it to a file and close the file.

13.2.1 Making Home Pages

Imagine that you and a group of your friends decide to make home pages, and you all want them to look identical to one another except for a few small details. The general problem is like the catalog page generator that we just solved. Let’s make a home page creator that can create many home pages, just changing the name and interests.

image Program 161: Initial Home Page Creator

def makeHomePage(name, interest):


  file.write("""<!DOCTYPE html>



<title>"""+name+"""'s Home Page</title>



<h3>Welcome to """+name+"""'s Home Page</h3>

<p>Hi! I am """+name+""". This is my home page!

I am interested in """+interest+"""</p>




Thus, executing makeHomePage("Barb","horses") will create:

<!DOCTYPE html>



<title>Barb’s Home Page</title>



<h3>Welcome to Barb’s Home Page</h3>

<p>Hi! I am Barb. This is my home page!

I am interested in horses</p>



image Debugging Tip: Write the HTML First

Programs to generate HTML can be confusing. Before you start trying to write one, write the HTML. Make up a sample of what you want the HTML to look like. Make sure that it works in your browser. Then write the Python function that generates that kind of HTML.

Modifying this program is painful, though. There is so much detail in the HTML and all that quoting is hard to get around. We’re better off using subfunctions to break up the program into pieces that are easier to manipulate. This is, again, an example of using procedural abstraction. Here’s a version of the program where we confine the parts that we’ll change most often to the top.

image Program 162: Improved Home Page Creator

def makeHomePage(name, interest):



  file.write(title(name+"’s Home Page"))


<h3>Welcome to """+name+"""’s Home Page</h3> <p>Hi! I am

"""+name+""". This is my home page! I am interested in




def doctype():

  return '<!DOCTYPE html>'


def title(titlestring):

  return "<html><head><title>"+titlestring+"</title></head>"


def body(bodystring):

  return "<body>"+bodystring+"</body></html>"

We can grab content for our Web pages from anywhere we want. Here is a program that can pull information out of a directory provided as input and generates an index page of those images (Figure 13.8). We’re not going to list the doctype() and other utility functions here—we’ll just focus on the part we care about. And that is how we should think about it—just the part we care about; we write doctype() once, then forget about it!

Figure 13.8 takes a little explaining. We ran the code that appears below by executing makeSamplePage(getMediaPath("")). Then, we opened the generated file “samples.html.” The generated page is all one line—which browsers have no trouble interpreting, but is hard for humans. We inserted some return characters to make it easier to read. The browser page to the right is what is seen when the HTML to the left is opened.



Creating a thumbnail page.

image Program 163: Generate a Thumbnail Page

import os


def makeSamplePage(directory):



  samplesFile.write(title("Samples from "+directory))

  # Now, let’s make up the string that will be the body.

  samples="<h3>Samples from "+directory+" </h3>"

  for file in os.listdir(directory):

    if file.endswith(".jpg"):

     samples=samples+"<p>Filename: "+file

     samples=samples+'<image src="'+file+'"height="100"></p>'



We can get content to add to our home pages from a wide range of sources. We could scrape information to add to our pages. In the previous chapters, we have built koan generators and random sentence generator. We can add something like that to our homepage generator. The function tagline randomly returns a tag line (a signature line) to the bottom of the home page.

image Program 164: Home Page Generator with Random Tag Lines

import urllib

import random


import urllib

import random


def makeHomePage(name,interests):



  file.write(title(name+"'s Home Page"))

  text = "<h3>Welcome to "+name+"'s Home Page</h3> "

  text += "<p>Hi! I am "+name+". This is my home page!"

  text += " I am interested in "+interests+"</p>"

  text += "<p>Random thought for the day: "+tagline()+"</p>"




def tagline():

  tags = []

  tags += #34;After all is said and done, more is said than done."]

  tags += #34;Save time... see it my way."]

  tags += ["This message transmitted on 100% recycled electrons."]

  tags += ["Nostalgia isn’t what it used to be."]

  tags += ["When you’re in up over your head, the first thing to do is close your mouth."]

  tags += ["I hit the CTRL key but I’m still not in control!"]

  tags += ["Willyoupleasehelpmefixmykeyboard?Thespacebarisbroken!"]

  return random.choice(tags)

How It Works

Let’s walk through the whole large example.

·         We are going to need both urllib and random in this function, so we import both of them at the top of our ProgramArea.

·         Our main function is makeHomePage. We call it with a name and a string of interests, like this:

>>> makeHomePage("Dracula","bats and blood")

·         At the top of makeHomePage, we open the HTML file we’re writing, then write out the doctype using the utility function. (It’s not listed here, but would have to be in the Program Area). We write out the title (using the title function) with the input name inserted.

·         We build up the body of the page in the string variable text. We break it up across several lines to make it more readable. To do that, we use a shorthand in Python. The syntax += means “Append the string on the right to the string variable on the left.”

Read the line:

text += "<p>Hi! I am "+name+". This is my home page!"


text = text + "<p>Hi! I am "+name+". This is my home page!"

Thus, we build up the body in the string text with a heading, a paragraph with the owner’s name, a statement about interests, and the random tag line. We write out the name and the return values from the functions by concatenating them into the middle of the HTML string. We then write that to the Web page body (using the body function).

·         The function tagline creates a list of strings (using the same += shorthand, but with a list of strings), then randomly chooses one (using the library function random.choice). Each time tagline is called, it returns a string with a random tagline.

·         >>> tagline()

·         "I hit the CTRL key but I’m still not in control!"

·         >>> tagline()

'Save time... see it my way.'

·         Finally, back at makeHomePage, we close the HTML file, and we’re done.


Frequently Asked Questions

Is it free to get my assignment evaluated?

Yes. No hidden fees. You pay for the solution only, and all the explanations about how to run it are included in the price. It takes up to 24 hours to get a quote from an expert. In some cases, we can help you faster if an expert is available, but you should always order in advance to avoid the risks. You can place a new order here.

How much does it cost?

The cost depends on many factors: how far away the deadline is, how hard/big the task is, if it is code only or a report, etc. We try to give rough estimates here, but it is just for orientation (in USD):

Regular homework$20 - $150
Advanced homework$100 - $300
Group project or a report$200 - $500
Mid-term or final project$200 - $800
Live exam help$100 - $300
Full thesis$1000 - $3000

How do I pay?

Credit card or PayPal. You don't need to create/have a Payal account in order to pay by a credit card. Paypal offers you "buyer's protection" in case of any issues.

Why do I need to pay in advance?

We have no way to request money after we send you the solution. PayPal works as a middleman, which protects you in case of any disputes, so you should feel safe paying using PayPal.

Do you do essays?

No, unless it is a data analysis essay or report. This is because essays are very personal and it is easy to see when they are written by another person. This is not the case with math and programming.

Why there are no discounts?

It is because we don't want to lie - in such services no discount can be set in advance because we set the price knowing that there is a discount. For example, if we wanted to ask for $100, we could tell that the price is $200 and because you are special, we can do a 50% discount. It is the way all scam websites operate. We set honest prices instead, so there is no need for fake discounts.

Do you do live tutoring?

No, it is simply not how we operate. How often do you meet a great programmer who is also a great speaker? Rarely. It is why we encourage our experts to write down explanations instead of having a live call. It is often enough to get you started - analyzing and running the solutions is a big part of learning.

What happens if I am not satisfied with the solution?

Another expert will review the task, and if your claim is reasonable - we refund the payment and often block the freelancer from our platform. Because we are so harsh with our experts - the ones working with us are very trustworthy to deliver high-quality assignment solutions on time.

Customer Feedback

"Thanks for explanations after the assignment was already completed... Emily is such a nice tutor! "

Order #13073

Find Us On

soc fb soc insta

Paypal supported