Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall 2004 Take Home Exam 2 Questions Page

Remember that you should not post code on this page!

Ask your questions here


Is JES closing itself when it runs your program? It could be because you are trying to create a really big picture. For example, makeEmptyPicture(10000000, 10000000) tries to create a picture 10 million pixels wide and high. Your computer can't handle a picture that size, so JES panics and quits. So check your code to make sure your math is right and you're not trying to create a super-big picture by mistake.

You may want to correct the page where it says "turn in your exam as exam1 in JES" – looks like it was just a cut-and-paste oversight (because TakeHome1 says the same thing).


Ok, corrected. Thanks for the input. Angela Liang

Okay, so basically this is similar to HW4 in that our function is to generate a webpage & the pics are to be scaled thumbnails, yes? (i.e. anyone can input a folder & it will generate a page w/just thumbnail pics?)

It's similiar but not quite. In hw4, you set the height tag to make the picture smaller but the browser still downloads the large picture in order to scale it. In this assignment, you need to actually scale the picture so the browser spends less time downloading the picture (since it's smaller). Therefore, you do not set the height tag in this assignment. Angela Liang

Just a stupid question in case of anything: Are partial credits allowed on take home exams?

The take home exams are graded just like any other assignment. You get credit for what you do. Like, in general, there will be some credit for creating an html file, and some more for generating images, and still more for adding the images, and links to the page, etc. The only difference, however, is that if you do not provide the "I did not give or receive help on this asignment" statement, you get an automatic 0. Kelly Lyons


When I try scaleImage and input a picture and a scale, nothing happens (JES closes).

Is there something wrong with the given function?
There shouldn't be anything wrong with the function. If there was, it would/should give you an error. If it's crashing JES, then that's odd, and could be a problem with your computer, or your JES just as easily as with the program. You should IM a TA or professor to get more specific help with this problem. Kelly Lyons

when you said round the dimension, can we just use the int()?

int() is a form of rounding, so long as it is used properly. Kelly Lyons

is the html page going to be generated in the same directory as the pictures like the previous hw?
Yes Kelly Lyons

what will the name of hour html file be?
index.html Kelly Lyons


if the ratio is off by .004, 0.003, 0.005 etc, is it okay?
Since pixels are only counted in ingegers, a ratio which is off by something that rounds to 0 is effectively correct in appearance, so yes this should be fine. Kelly Lyons


whenever I set the max dimension, for a number, the final result has the max dimension as number+1, for example if the maxD was 100 and the dimensions was 200 by 50 I would get 101 by 26, can you please explain why this may occur?
Generally off by one errors are caused in for loops where the increment goes one too many or one too few. But there could be other reasons. I suggest you trace the code on paper. It should help you find the error. Kelly Lyons

On explorer the reduced image has the right dimensions but it has black areas around it,its like a pic with a black rectangle
Remember when you make an empty picture, it is created as a black canvas. Could it be that you are making a picture larger than picture you are copying into it, thus leaving black on some edges? Kelly Lyons


Yes I have a similar prob, I have a black image that links to the regular big pic
The reduced images is created by your scaling function. So if it doesn't look right, then I would check your scaling function to see if it is working properly. Kelly Lyons

do we define maxedge, go ahead & input a #, or is that something that the user of the function decides? (ie, def thumber(directory, maxedge) or def thumber(directory, 100)?

So, for the pics where the largest dimension is 100, we just have it display the original pic?

Okay, here's where I get stupid: I never quite remember/understand how it is that I check my program, as far as the inputs are concerned, to see what shows up.
Reread the assignment – we always tell you what inputs there are. Mark Guzdial

I need help with the writePictureTo function
I keep getting an error in that line when I try to run the function, eventhough JES saves the code.
Page 54 in the book. Mark Guzdial

is there anyone out there to offer advice????? gtg075e
Not advice – we can only answer questions about topics in the class (not about your exam or your assignment) and clarifications about the assignment. Mark Guzdial

when is the take home exam due?

Look on the syllabus Angela Liang

I want to look at my HWK 4 and 2 to remember how I did it, how do you unzip a file?


My program works for only the barbara.jpg and none of the other files. What's up with that?

Open up the zipped file and then look under the "File" menu. There should be an option to "Extract all files". Or, you can just cut certain files out of the zipped folder and paste them elsewhere on your computer if you want. As for the program only working for barbara, make sure that you haven't hardcoded a certain picture anywhere, or that your other files are also ".jpg" files. Summer McWilliams

I just copied the example program as is and when I try to use a .jpg file for the input I get an error that says "the input is not a picture". Do I have to make the file a picture before I can get the height etc.?

Yes. In general, files don't have a height. Pictures do. Mark Guzdial


What does "The thumbnail will have the original
file name with tn_ prepended." mean? Should it be tn_filename.jpg or filename_tn.jpg?

pre means before, so tn_filename.jpg would be correct Kelly Lyons

nevermind


to run it, do i do thumber(path of media sources, ##)
To run it you can enter ANY directory, not just mediasources, and yes any number (bearing in mind that the number is representative of a max edge pixel size, so things like -1 wouldn't make sense) Kelly Lyons

is there somewhere in the book or in the lecture slides that talks about scaling?
Yes, but I don't know where off the top of my head. It turned up on the midterm 1 review, so I'd look previous to midterm 1 material. Also, the sample function given on the exam is worth looking at seeing as it does exactly what you need it to do Kelly Lyons

if i put in 200 as my maxedge, and the picture ends up being 201 does the one pixel matter - if it does, how should i compensate for the rounding, etc errors?
If 200 is the maxedge, then the picture should not end up being 201. There is some error in your scaling function I would assume. You should check your code and see where it does this, and fix it. Off by one errors are generally easy to fix and are generally created in for loops. Kelly Lyons

I cant even get the ziped file to open on my computer, that's the problem. there definitly is not a "extract all files" option under the normal jes file pull down window. how do I resolve this
You can't extract zip files with JES. You need Winzip to do this. If you find the zip folder on your computer (and you have winzip on your computer) you can right click on the folder and find an "extract all files" option in the menu. You would want to click that. If you are still confused, try going to office hours or IMing a TA Kelly Lyons

do we need to have a getMediaPath command
The directory is inputted, so you should use that, and not need a getMediaPath command. Kelly Lyons


Side Note: PLEASE DON'T CHEAT!

We are now investigating some 20 academic misconduct cases for suspected cheating on Take Home Exam 1. We will do a similar analysis for Take Home Exam 2, but we probably won't have those results until near the end of the term. If you don't want to be dealing with academic misconduct cases and an "I" at the end of this term and start of next, DO NOT CHEAT ON TAKE HOME EXAM 2!! Mark Guzdial


so if the original file's largest dimension is less than 100 OR less than the max edge, just copy the original as tn_? or was the 100 part just the example?
100 is also just an example. If your maxedge input was, say, 200, then you wouldn't need to create a thumbnail for pictures who's largest dimension was less than 200. Kelly Lyons

If the largest dimension is less than or equal to 100 then no thumbnail needs to be created but a copy of the original image can be made and named as per above (i.e. tn_originalname.jpg).

This means you can either copy the original (small) file to tn_orginalname.jpg or you can reference the original filename directly from your thumbnails page. Missing Page

i mean should we do that both for when the largest dimension is less than 100 as well as when the largest dimension is less than maxedge?
100 is also just an example. If your maxedge input was, say, 200, then you wouldn't need to create a thumbnail for pictures who's largest dimension was less than 200. Kelly Lyons

I went to test part of my code and every time i hit enter after typing it in the command box, my JES closes itself. ACK!! What do I do? I've restarted the computer and that did nothing.

I find that JES closes itself if you ask it to do something that requires GOBS more memory than the computer has. Maybe you need to run one of the lomem versions of JES, or try it on a computer with more memory, or close some of your other applications. Mark Guzdial


the same thing (as above) happens to me as well.


i tried closing other applications and on another computer and it still closes


my thumber function takes in three inputs (file, directory, and maxedge). Is this ok or do i need to make it only have two?
Just two inputs. Directory and Maxedge Greg Leo



Jes keeps on shutting down whenever I try to use the function that is given, scaleImage.

JES will do that if you try to make a really, really big picture. It runs out of memory and java failsBill Leahy

is the ScaleImage code doing what the instructions ask for? or do we have to modify it so that the picture ends up with 100x75 if the maxedge given is 100 for example?
The supplied code only scales an image by a input factor. You will have to figure out how to modify the code to scale to a maxedge, and then apply it. Greg Leo


Any ideas as to why my program just runs, and runs, and runs some more w/o stopping (or atleast I stop it beforehand)
Remember that for loops take a long time to run. Check and see if you've got a lot of those running inside eachother. Also, what size directory are you running it on? If it is very large, then it might take a long time to run. Try using a directory of one picture or two to see if that is the problem. Kelly Lyons


When I makeEmptyPicture(200,300) and save it as a file, when I look at the file the dimensions of the picture automatically become 201 x 300 instead of 200x300, why does this happen, is it okay if I turn it in like this or is it a computer problem??? Help please! I even tried it in the command area and the same thing happen, so do we have to subtract one from the width and height before putting the dimensions in the makeEmptyPicture func??
That's okay...it's a JES thingBill Leahy

When I use the scale function it always goes out of bounds, would a if statement be necessary?

Try printing out the size of the picture that JES is trying to createBill Leahy

can we assume that max edge will be given as 100.0?

^ No.
max edge can be any number >=1. Make sure it works for any input!! Kelly Lyons

I did my HW4 at home, not at school. How can I get a copy of it?
Save it on a disk, or email it to yourself are the easiest ways to do that. Kelly Lyons

My multiplier rounds up/down to 1/0, how can I maintain the decimal places?
I'm a little confused by what you are asking. You don't want decimal places becuase pixels are all integers. Kelly Lyons

Is there any way to get JES to be more specific when about where my syntax error is? It tok me 5 hours just to fix everything in my code when i was trying to load it and it gave me errors, but those errors at least tell me where the prblem is. Now that I've loaded it, all it says it that I have a syntax error...AHHH!!!
You can try running it in expert mode. That sometimes gives you a more specific error. Also, if the syntax error gives you a line number, check the line above. Also check that all your parentheses are matched correctly, colons are at the end of all def, for and if statements, and things are indented correctly. Those are the most common syntax errors. Kelly Lyons


If I never get it fixed, to a point where it will actually run, can I still get a decent grade if most of my code is right?
When we grade your assignment, if it doesn't run, then the most points you will get is a 60. We'll go through and run parts of the code to see what does work, add up all the points you got and multiply it by .6 This of course means that if you can turn in code that runs, even if it doesn't do everything, you will almost always get a better grade than if you turn in code that does not run. Kelly Lyons


When the TA's check the our exam are they going to input for example 200. for the maxedge or will they just put 200? Jason Nelson
Just 200 Remember that maxedge represents the number of pixels in the edge, and pixels are always integers. Kelly Lyons


Ask your TA to get a copy of your homework 4 for you. If you have a syntax error that you can't figure out, start commenting-out lines or cutting them out (paste them into Word, then paste them back later) to figure out where the error is (see page 226). If your program doesn't run, you can't get more than half the credit – you're best off turning in something that runs, even if incomplete. Mark Guzdial


Regarding the comment above from Mr. Guzdial: so you're saying that we are better off having code that atleast generates a wepage with pics as opposed to having code that attempts to do all of the scaling for the thumbnail pics but fails to run?
YES! Kelly Lyons

When I makeEmptyPicture(200,300) and save it as a file, when I look at the file the dimensions of the picture automatically become 201 x 300 instead of 200x300, why does this happen, is it okay if I turn it in like this or is it a computer problem??? Help please! I even tried it in the command area and the same thing happen, so do we have to subtract one from the width and height before putting the dimensions in the makeEmptyPicture func??
That's okay...it's a JES thing Bill Leahy
SO DO YOU MEANS ITS OK IF I HAVE 201X301 INSTREAD OF 200X300?

Apparently this is a JES error, and so it is ok if your picture is off by 1 pixel like this. Kelly Lyons

thank you




Hi- I was able to get JES to run the scaleImage function, but I did not get a output. I looked to see if it created something, but it gave me a response:
(JES response)
Why? How can I see this media.Picture.?
I even typed show(picture) but didn't work

You must save the picture in order to show it. The media instance means that your function returns something that you do not save. You should try running picture = function() and then do the show(picture) Kelly Lyons

Also, I'm pretty sure the scaleImage function will allow JES to create a smaller version of a jpg file. If it does create a smaller version, how do I go about putting the smaller version of the picture into my directory folder (by using the "wt"?)
Thanks for taking the time to read this.
To save something to a directory, remember that there is a writePictureTo function in JES Kelly Lyons

my function runs, but it just creates a new file that is completely blank, all it has is a black box where the picture is supposed to be. this has to be something that i'm doing wrong with the copying the pixels from the original to the thumbnail. any suggestions?
You are correct that there is an error in copying the pixels. Check the code where you do the pixel copying, and see what's wrong with it. Kelly Lyons

was the response
(sorry- I must have deleted it before posting question)

the response was media instance at some value

for the equation:
scale=xlength/maxedge
how do i keep scale in decimals. I get integers for scale.


nevermind i figured it out

Question,

i try to keep my decimals till the end of my opreation. But JES takes all the division into integers. That means 2 may equle to 2.74, for example. How to fix that?
Try multiplying by 1. (notice the decimal point) in all of your calculations Kelly Lyons

in order to make accurate thumbnails, i need to input 100.0 instead of 100. (because of the decimals) is that okay?
That is fine, but remember that 100 is just an example. maxedge could be any number and you have to account for this. Kelly Lyons

In my program, the function will execute if certain values are expressed explicitly as numbers, but it doesn't run if I define those values in terms of other variables (which represent numbers). Any reason why?
No idea. You should be able to define a variable in terms of another variable provided the other variable exists in the function. You probably have an error somewhere. Kelly Lyons

Need some help with nested for loops, book examples? Slide examples?


The function float takes in any number, and returns the floating point version of that number. float(100) gives you 100.0. Mark Guzdial


Any help on linking the smaller image to the larger one?
In HW4, how did you link a picture to another picture? Check the HTML, and see what the picture.jpg really means. Kelly Lyons

Review your home work 4 code Greg Leo

When you type 1.0*(1/3) into JES, it returns 0.0. However, we all know that 1.0*(1/3) is really 0.333333333. What would you type in JES to get it to return 0.333333333 and not 0.0?
The 1/3 will return 0, and 1.0*0 is 0.1 How about 1.0/3.0 and then try it. Kelly Lyons

I think I have everything well and figured out as far as all of the code is concerned. When I decided to fully test my code, however, it seems to give preference to certain .jpg files, leaving others completely unmanipulated. Can you think of any reason why this would happen?
Many things could cause this. Trace your code. Kelly Lyons

I tried to call the output of a function that I returned from a previous function but it wouldn't work. Can someone tell me why?
It depends. What is it that it returns? Are you treating it as the same thing in your other function? i.e. you can't return a picture and then treat it as a file. See what the error is. It should be helpful in this instance. Kelly Lyons

I had trouble displaying my final product html on Firefox (the images were tiny vertical rectangles on the left side of the page), but it worked fine with Internet Explorer. Is there any particular reason that Firefox didn't work? And anyone that is having the same problem, try it on Internet Explorer.
Will Smolenski gtg608y@mail.gatech.edu
It's probably got something to do with the formatting of firefox. If it works in IE, then you should be fine. Most TAs will be running it in IE, and just in case, in your notes to TA, let them know not to run it in Firefox. Kelly Lyons

When i run my code it says media.Picture instance at 21624904 and doesn't display any pictures on my html page. What could i be doing wrong?
The media.Picture instance means it returns a picture. If it's not displaying pictures, then look at the source from the html page, and see what it has in it. Kelly Lyons

my program runs, and it creates a thumbnail with a link to the parent image. however, the thumbnail comes up with the little red x and no pic. how can i fix this?
The little red x means it can't find the picture. Check the html produced from your function. Kelly Lyons

did anyone else wet themself the first time it finally worked right?
Congrats on getting it to work.... Kelly Lyons

can you use two if statements back to back??
You can use an if statement within an if statement, you probably did this in HW4. Greg Leo

would there be any particular reason the statement would not be legal jython...JES won't let me load it.

sorry, would there be any particular reason the statement !DOCTYPE...etc would not be legal jython? Jes tells me it isn't
That's HTML. HTML won't load in Python. Do you have it inside a string? It should work in that case Kelly Lyons

Hi.

I have a slightly different scaling problem. Instead of by problem being an imput of 200 returning a dimension of 201, my 200 returns 206 or 210. By using the print command on my scale number, I figured out that JES is making my scale a whole number and not the true decimal quotient. However I have specified no integer restrictions anywhere in the code. What can I do to get JES to return a decimal?
JES assumes integers if none of your inputs are decimals. Try making one of your inputs a decimal, i.e. 1.0 Kelly Lyons

Sigh, now the JES is telling me I have wrong spacing when i know it is right. Sometimes i want to run over this stupid snake.
Check your parentheses. Kelly Lyons

How do you call the output of one function and use it in another function? For example, if I have a function that is used within my thumper function (like the returned picture from the scaling function).The returned output is a picture and i'm using it as a picture.
outerFunction(innerFunction(input)) Missing Page

The spacing thing happens to me also. Sometimes it goes away if I rewrite the code and the code surrounding it. 0_o
Sometimes "spacing" errors in JES are caused by syntax errors. E.g. the spacing may look correct, but there may be missing punctuation somewhere (missing colons, unmatched parens, unmatched quotes...). Missing Page

when testing the code, what do you input for "directory"? for some reason i keep getting errors.

The complete link to your folder.

Okay...I have a function which scales the functions properly and another function that generates a page of jpg pics which are links. The scaling function uses writePictureTo; however, I try to recall the new files made from writePictureTo in my html of my second function. However, this doesn't work. Is there another way to relate they two functions or insert the thumbnails produced by the first into the second?
So, you are making all of the thumbnails and then trying to write the html? Perhaps you could do both more or less at the same time?Bill Leahy

So I used the internet a lot to help me on this assignment with the whole decimal problem(ie. www.python.org.) Is that ok?
YesBill Leahy

So I'm testing my code with a folder full of different size .jpg pics, however, some of them cause "array out of bounds errors." The weird thing about this is that pics of the same size (and larger or smaller)work. I know this b/c i have tested my inner fcn on individual pics and have isolated which ones cause trouble. Any ideas on why this happens? Is this a me error or a computer error?
Hard to say based on the information you have supplied but it might be an error in the logic you are using to figure out how to scale the pictures. You might try having the program print out the original size of the picture and what you want to make the size of the thumbnails and see if that all makes sense.Bill Leahy

when you were to scale a picture...how do you copy it and rename it???
The scale function we gave you creates a new picture. Why do you want to copy and rename it? Why not just save it under whatever name you want?Bill Leahy

My program runs without giving me any error message but when i open the html file, it's blank! AHHH

What could be wrong?
You open the file, write to the file and then close the file. If the file is empty check your program logic and make sure those statements are actually being executed (i.e. you could add in some print statements just to see what is happening but be sure to take them out later!Bill Leahy

AHHHHHH forget 1316, I can't even do this.!!!!!
Don't give up. Kelly Lyons

i've made a function that will print out the link from a thumbnail to its bigger image, but how can i tell the function to identify the thumbnails out of a list of pictures? i know that i can use "if file.startswith("tn_"):" to single the thumbnail out, but then how can i match that up with the printng of the link?

nevermind

What does this error mean: An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.
in function scaleImage
TypeError: __div__ nor __rdiv__ defined for these operands
Are you passing in a picture and a number into scaleImage?Bill Leahy


the statement- "Produces a new picture "scale" times the size of the picture passed in" imply that original picture multiplied by 'scale'= dimensions of condensed picture

What's the difference between scale and maxedge? [scale is the amount of change of the original and new; maxedge is the maximum value of either the height or width] How am I able to set the new dimension with the if statements? How can JES go about creating them?
I don't understand your question?Bill Leahy


Ok, i've read these postings a hundred times now, and i still cannot understand what to do when JES closes out when i'm running it.
It means you are making a very large picture, and alocating a lot of memory. Check your code (before you run it) and see where you are making pictures. Are you making very large pictures accidentally?

I can make the page with the thumbnails, even link to it...but the source refers to both the thumbnail and its link as: tn_pic.jpg. I've tried defining a new variable and putting it in the for loop, but it will just keep resizing the picture forever. I've tried putting it outside the for loop, but it won't recognize it. Any suggestions?
Find where you are writing the ... portion. One of the ... references needs to be changed. Kelly Lyons

JES somehow deletes the variable I define when making the link from the thumbnails to the real pictures. Where can I define it in the function so it will recognize the variable when I try to use it? Is there anyway to permanently define variables?
You need to define the variable within the function you are using. If you define it within a loop, then it's not recognized outside the loop. Kelly Lyons

If JES closes out when you're running, check what you're passing as input to makeEmptyPicture or makeEmptySound. The numbers are too big, so the picture or sound you're creating is so enormous that all of memory is used up and Java crashes. Mark Guzdial


what does it mean when a piece of code in <> is a different color?

I am having a hard time getting the files to save in the directory when using the scaleImage function. Will the TA's be using setMediaPath() for this code also? Because if I set the media path to the directory, then everything works fine.
No, the TAs will not use setMediaPath. Remember that the function takes in a directory. Use this instead of the media path. Kelly Lyons


I had problems before with my program selectively picking which JPEGS I put in my test folder. When I used mediasources pictures only, everything worked fine. Could there just be some issue with my own JPEGs?

What does it mean when a piece of code in html <> is a different color?

I had no problems with my homework 4 index page, and I am using my code for opening, writing, and closing that I wrote for hw4. My thumber program creates index.html, but it will not write anything to it at all, not even the opening lines. Is there some setting in windows XP or explorer that I need to change? I have tried everything that I know!!!

(con'td from above)- my program writes the tn_files to the same directory and scales them correctly, its just the html part that doesn't work.

How do you take a numerical input (maxedge) that is say 100 and make JES recognize it as an integer and not a string? I can't find anything about this in the book or the lecture slides.

What does the line "oldx = max(1, int(x/scale)) do?

When I run my program It doesn't produce the tn_filename.jpg files but it replys with media.Picture instance...

>>> thumber("C:\JES\MediaSources\mediaout", 100)
<media.Picture instance at 11032120>

Is this an error or is the program working fine? If it's an error, how do I find where the error is.. and if it's not, why is the program not doing what it is supposed to do?

when I try to write to the html file i get this error
You are trying to access a part of the object that doesn't exist.
Please check line 56 of C:\JES\thumberstuff\thumber.py
can anyone help?

how exactly do you write the filename of the new thumbnail to the directory. I get the writePictureTo fuction, but in the slides i found this
writePictureTo(picture,dir+"//"+"titled-""tn)"+file) but i can't figure out how to prepend tn_ to that. Its probably really easy and I am just not thinking but...help please.

I love how when I run the program you gave us to use, scaleImage, it gives me errors.

my code only works for an maxedge of 50. else it says there is a ZeroDivisionError: integer division or modulo. what does this mean?

It give you an error because you don't have a picture as an input you are using a file probably. Files have no height or width as the professor posted above.

no its a picture i put in... it gets an error on line 16 where it is oldx=

ok, ya'll may think that this goes really far back, but im having some real trouble not with the scaling part, that part i get, but with the makeSamplePage command! I keep getting the computer saying that there's something wrong with what im doing and i just don't know what the heck is going on! HeLP!!!

see pages 275-276


how exactly am i supposed to specify that only the pictures > 100 pixels on the longest edge are scaled down? i know it's an if ... > 100 statement, but do i say "100 pixels" or just "100"? I'm so lost!

There is an example that you can use on pages 397-401.

uh.... pgs. 397-401 in our book at least are the index!


did ya'll mean 297-301? because that has the moon kids example on there, which helps as well. I just had to check along the same last digits, hehe! THANKS A MILLION!

ok, im working with this right now, and i keep getting that there's an error in the file.write(title... line! The only thing is that I have checked the book like a million times and im still getting that error even though i did it right! for one thing, figure 11.7 is quite confusing for me, what does that part mean?



Link to this Page