Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

minimallinux Group Title

On week 2 beginning 'Iteration', I get an error on the print statement see below http://pastebin.com/raw.php?i=sFhLznUw Any one know why ?

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i don't get an error what did the traceback say?

    • 2 years ago
  2. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @minimallinux check your spelling. Python is case sensitive:P

    • 2 years ago
  3. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    File "<stdin>", line 4 print (str(x) + '*' + str(x) + '=' + str(ans)) ^ SyntaxError: invalid syntax >>>

    • 2 years ago
  4. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    itersleft = itersLeft - 1 << wrong spelling

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

    Fixed that still error x = 3 >>> ans = 0 >>> itersLeft = x >>> while (itersLeft != 0): ... ans = ans + x ... itersLeft = itersLeft - 1 ... print (str(x) + '*' + str(x) + '=' + str(ans)) File "<stdin>", line 4 print (str(x) + '*' + str(x) + '=' + str(ans))

    • 2 years ago
  6. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    print (str(x) + '*' + str(x) + '=' + str(ans)) >>>>> print(str(x) + '*' + str(x) + '=' + str(ans)) might be this too (the space betweent print and parenthesis)

    • 2 years ago
  7. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    between*

    • 2 years ago
  8. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Does't seem to be a problem on other print statements, seem to get error whichever way I try it, even copy paste original code !

    • 2 years ago
  9. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ie. the file I download produces error

    • 2 years ago
  10. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    hmm let me see again

    • 2 years ago
  11. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i just saw ...are u doing it in IDLE or on a new file? i mean for me even without touching the print statement it runs properly.

    • 2 years ago
  12. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    >>> while (itersLeft != 0): ... ans = ans + x ... itersLeft = itersLeft - 1 ... print (str(x) + '*' + str(x) + '=' + str(ans)) thats too much for IDLE i think...i believe u are supposed to write that long code into the other python window and then run the whole from there. i wrote the code in the IDLE and it gives me the same error it gives u.BUT, if i write it into the code window(or help me here how it is called) it works fine.

    • 2 years ago
  13. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    No I don't use idle just standard python shell

    • 2 years ago
  14. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ok w8 i confused the python windows names. i wanted to say that ,when i used the shell it gave me error....but if u use [File>>>New Window] and write it there it runs normally.

    • 2 years ago
  15. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I've got 2.6 and 3.3 and both show error

    • 2 years ago
  16. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    did u do it like i told u? on shell window go file>>>New Window then write ur code there and press f5 (to run it).

    • 2 years ago
  17. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ill try

    • 2 years ago
  18. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    same in idle, error in syntax even with the original file

    • 2 years ago
  19. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Getting a little baffling

    • 2 years ago
  20. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    hmm dont know how to help u :( works fine for me...could u pass some screens maybe somehow?

    • 2 years ago
  21. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes I will attach a screenshot if possible

    • 2 years ago
  22. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Using what I see here, if I duplicate it I can get the same error in the python shell unless I hit <enter> again before the print so the ... changes to >>> Can't duplicate error in idle. x = 3 >>> ans = 0 >>> itersLeft = x >>> while (itersLeft != 0): ... ans = ans + x ... itersLeft = itersLeft - 1 ... print (str(x) + '*' + str(x) + '=' + str(ans)) File "<stdin>", line 4 print (str(x) + '*' + str(x) + '=' + str(ans))

    • 2 years ago
  23. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    So I have attached iterate.jpg, a screenshot of my python shell running the code to an error

    • 2 years ago
    1 Attachment
  24. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    minima btw do u use the suggested version of python? i mean might that be the problem? http://www.enthought.com/products/epd_free.php

    • 2 years ago
  25. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I have both 2.6 and 3.3

    • 2 years ago
  26. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I prefer just the shell, it should work

    • 2 years ago
  27. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    suggested is 2.7 and in the screen u r using shell (i think) not the window i told u to try.

    • 2 years ago
  28. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    As above I can duplicate what your image shows but hitting <enter> again like I said makes it work

    • 2 years ago
  29. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes just the shell but it SHOULD work

    • 2 years ago
  30. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    OK Ill hit twice

    • 2 years ago
  31. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    xD tell us what happens when u hot twice:P

    • 2 years ago
  32. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    No I get the error even then

    • 2 years ago
  33. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    It must be something simple

    • 2 years ago
  34. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    when i paste thsi into shell: x = 3 ans = 0 itersLeft = x while (itersLeft != 0): ans = ans + x itersLeft = itersLeft - 1 print(str(x) + '*' + str(x) + '=' + str(ans)) i get no error...but i dont get any answer either:P thats crazy xD

    • 2 years ago
  35. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    if i try to write command per command it gives me the error

    • 2 years ago
  36. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    good idea:)

    • 2 years ago
  37. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @msmithhnova ok i now got what u meant by enter twice yes it works for me aswell now.

    • 2 years ago
  38. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    no i believe u just didnt do what msmith says. before u write the print statment enter wtice so u ge the >>> then write the print statement.

    • 2 years ago
  39. msmithhnova Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Yeah the way I look at that is since you didn't hit enter again to exit the while loop code it thinks it is still in the while loop but then it gets to the print which is not indented and realizes it isn't. So now it goes "ok i am in the loop but i'm not in the loop, huh" , throws it's virtual hands up in the air and says "I give up" (syntax error)

    • 2 years ago
  40. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    hahhahah poor code!!!

    • 2 years ago
  41. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ... yes, you need to enter the print statement at a shell prompt you haven't let the interpreter execute the while statement/suite and it doesn't like that at all. the shell lets you enter multiline compound statements but if you try to include something 'outside' of the compund statement it will complain http://dpaste.com/810233/

    • 2 years ago
  42. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    did you see my code paste?

    • 2 years ago
  43. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    the problem is definitely an indentation problem. you have entered a multiline compound statement into the shell the print statement has been entered before the shell can process the compound statement BUT the print statement indentation places it outside of the compound statements execution suite the shell doesn't like this so it complains. try typing all that into a text file and running the file/module/script from the shell - do linux files need an extension (.py)?

    • 2 years ago
  44. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Sorry folks, it is not suspect i just got it working by running it as a file in normal shell (the equivalent of running in idle) as opposed to typing into a python shell here is my result [anton@Centos ~]$ python iterstest.py 3*3 = 9 So sorry for the accusations, recriminations and the loss of around 3 hours !

    • 2 years ago
  45. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    bwCA is right

    • 2 years ago
  46. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I can put 3.3 back on now

    • 2 years ago
  47. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yeay - i don't bother much with the command prompt shell so i had to try it for myself

    • 2 years ago
    1 Attachment
  48. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm not keen on the idle so I will run them as file in shell

    • 2 years ago
  49. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    So we have to be careful of typing into shell with multiline statements

    • 2 years ago
  50. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yep the shell only executes one 'statement' at a time. it recognizes compound statements and allows you to enter the multiple lines it (apparently) recognizes that you are done with the compound statement when you enter a blank line - then executes it if you mess up and enter two separate statements it identifies it as a syntax error don't stop using the shell tho, it is a great way to try things out and see if they work. now you know about compound statements in the shell so keep using it. when you are writing a program in a file and having trouble with it, the shell is a great place to try bits and pieces of it to narrow down the problem - often you can write simplified versions of your code in the shell to test out structure or logic and it is very convenient

    • 2 years ago
  51. minimallinux Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    And my equivalent of idle is to put it in a .py file and run it with the python command

    • 2 years ago
    • Attachments:

See more questions >>>

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.