anonymous
  • anonymous
I am working on the "while" function in Lecture 2. When I type "print y" (without the quotes), I get a syntax error. Does anyone know why?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Owlfred
  • Owlfred
Hoot! You just asked your first question! Hang tight while I find people to answer it for you. You can thank people who give you good answers by clicking the 'Good Answer' button on the right!
anonymous
  • anonymous
can you please put the rest of the while loop and I'll try to answer
anonymous
  • anonymous
>>> y=0 >>> x=3 >>> itersLeft = x >>> while(itersLeft>0): y=y+x itersLeft=itersLeft-1 print y SyntaxError: invalid syntax

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
I think because you haven't indented it correctly. the line y = y + x should be tabbed in also the next one
anonymous
  • anonymous
Hmm. on my screen in Python, those two lines are indented, but after copying them into the chat box, they are no longer indented...
anonymous
  • anonymous
I'm not sure, when I run it, it comes up with 9
anonymous
  • anonymous
That's strange. I guess I'll just keep trying. Thanks for your help Joz!
anonymous
  • anonymous
are you sure they are not in line with while? I'm just saying, because the print y is further left on the chat box
anonymous
  • anonymous
in my python interface, "y=y+x" and "itersLeft = itersLeft - 1" are both indented to the right of the "while" statement. "print y" is to the left of the while statement
anonymous
  • anonymous
yeah, that sounds right to me. When it comes up with the error, is there a pink thing on the script part?
anonymous
  • anonymous
This is basically my first time programming, so I'm not exactly sure what you mean by script. "print" is highlighted in pink, and below that it says "SyntaxError: invalid syntax"
anonymous
  • anonymous
hmmm... try lining it all on the left hand side, except the 2 lines under while. Failing that, I don't know.
anonymous
  • anonymous
ok i'll give that a shot. my last question for you - how do i line everything up on the left side? every type i start a line, it starts with ">>>"
anonymous
  • anonymous
wait... are you doing it straight into the shell?
anonymous
  • anonymous
try to find the IDLE page. give me a minute and I'll tell you the path to find it...
anonymous
  • anonymous
well, i feel like an idiot. As I was watching the video lecture, I noticed my screen looked different, but I ignored it. You're right, the top of my screen says "Python Shell"
anonymous
  • anonymous
is it a white screen, yeah? (Don't worry, I did the same)
anonymous
  • anonymous
just go to file, new window. If you don't have an option bar on the top, let me know
anonymous
  • anonymous
ahh - that gave me a blank screen. i typed in the code, saved, and clicked "run module" and that gave me the right output for y (9). Thank you so much for walking me through this
anonymous
  • anonymous
Haha no worries, you are set up now...
anonymous
  • anonymous
also make sure when you save, you save as name.py
anonymous
  • anonymous
ok got it. thanks again...

Looking for something else?

Not the answer you are looking for? Search for more explanations.