While your'e at it: exercise three of nineteen


#1

num = 1

while num <= 10:
print num ** 2
num += 1

I wrote the code correctly, but instead of passing me, it results in an infinite loop that crashes my computer browser. I am inquire as to how I can resolve this problem so I can receive accreditation for passing this exercise.


#2

The code doesn't run on your computer, it's sent off to a server. It seems unlikely that regardless of what the code does, that it would have any effect on your browser.
If the problem is with your code, then you'll need to post it. What you posted will not run at all, it isn't valid Python code.


#3

That is strange because it isn't rejected. It runs, but it does not complete itself.


#4

I belive that ionatan meant, that this code doesn't look like proper Python code, for example there are no indents
It's much easier to help, when code looks properly,

num = 1

while num <= 10:     # Fill in the condition
    print num**2     # Print num squared
    num += 1         # Increment num (make sure to do this!)

To do so, just paste your code, select it and use </> from the toolbar over the message window.


#5

Programs that don't terminate are supposed to get killed on said server, and a pop-up should show up in your browser (not a browser-window pop-up, just on the site page itself) saying it took too long to finish. Maybe your browser reacts poorly to the pop-up, the browser might not be tested by codecademy or some extension might be a bit wobbly. (I use chromium, firefox should be fine too, and chrome, which is built from chromium)


#6

I was and am using google chrome. It might be the other possibilities you have listed, but if not, that is strange that the exercise was not marked "incorrect".


#7

Hi @tepw115 ,

Because the code that you posted is not formatted, it is difficult for other users to read and debug it. After code has been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. Alternatively, you can place three backquotes on the line before the code and three backquotes on the line after the code. This will enable us to see important details, such as the indentation and underscores. If you use the backquotes, your code will be color-coded, making it especially easy to read.

Make sure that the code you submitted is indented correctly. If you do not indent this line, you will have an infinite loop ...

num += 1

That is because without its being indented, the line is outside the loop, and num will not get incremented.

For the loop to terminate properly, your code should look like this ...

num = 1

while num <= 10:
    print num ** 2
    num += 1

#8

I resetted the code and refreshed the browser, then changed it from "num <= 10" to "num < 11" and all of a sudden it passed me. I want to mention that I did this before in an effort to correct the problem, but it resulted in the code running and not completing itself. Overall, the problem is some how resolved.