A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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?

  • This Question is Closed
  1. Owlfred
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    can you please put the rest of the while loop and I'll try to answer

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    >>> y=0 >>> x=3 >>> itersLeft = x >>> while(itersLeft>0): y=y+x itersLeft=itersLeft-1 print y SyntaxError: invalid syntax

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I think because you haven't indented it correctly. the line y = y + x should be tabbed in also the next one

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hmm. on my screen in Python, those two lines are indented, but after copying them into the chat box, they are no longer indented...

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm not sure, when I run it, it comes up with 9

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    That's strange. I guess I'll just keep trying. Thanks for your help Joz!

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah, that sounds right to me. When it comes up with the error, is there a pink thing on the script part?

  11. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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"

  12. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    hmmm... try lining it all on the left hand side, except the 2 lines under while. Failing that, I don't know.

  13. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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 ">>>"

  14. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    wait... are you doing it straight into the shell?

  15. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    try to find the IDLE page. give me a minute and I'll tell you the path to find it...

  16. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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"

  17. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    is it a white screen, yeah? (Don't worry, I did the same)

  18. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    just go to file, new window. If you don't have an option bar on the top, let me know

  19. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  20. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Haha no worries, you are set up now...

  21. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    also make sure when you save, you save as name.py

  22. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ok got it. thanks again...

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.