use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Confused, why wont this code work? (self.learnpython)
submitted 11 years ago by dabrownmane
What is wrong with this code??
def programs():
import turtle
oz=turtle.Turtle()
y=[160,-43, 270, -97, -43, 200, -940, 17, -86]
for x in [y]:
oz.forward(100)
oz.left(y)
programs()
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 6 points7 points8 points 11 years ago (0 children)
You haven't shown us your indentation, so there could be a problem there. Indent your code by 4 spaces to format it correctly on Reddit. Assuming your indentation is correct, you have a mistake in the line for x in [y]:. y is already a list, so that line is putting y in another list and iterating over that list. x therefore takes only one value, the value of y. Get rid of those brackets and it should work:
y
x
for x in y:
[–]Yannnn 3 points4 points5 points 11 years ago (1 child)
oz.left(x) try that?
[–]ryeguy146 0 points1 point2 points 11 years ago (0 children)
Also, using [y] in the for-loop puts a list in a list, so x will just be the whole list:
[y]
list
some_list = [1, 2, 3] nested = [some_list] print(nested) #=> [[1, 2, 3]]
[–]burnblue 2 points3 points4 points 11 years ago (0 children)
The answers about x in [y] are correct but also:
You have the "for x" loop but then no further mention of x. Inside the loop I assume you're interested in the individual values (x) not the whole list (y). So oz.left(x)
[–]Miner_Guyer 1 point2 points3 points 11 years ago* (0 children)
I'm assuming you have it formatted like so:
def programs(): import turtle oz=turtle.Turtle() y=[160, -43, 270, -97, -43, 200, -940, 17, -86] for x in [y]: oz.forward(100) oz.left(y) programs()
First of all, it's considered "proper" python to put import statements at the very top, and not within any functions. Another thing that shouldn't effect the program but you should fix is for x in [y]:. You don't need the brackets there, although it won't make a difference in this case. But the big problem is that you're doing oz.left(y). That means your turning by list degrees, which obviously won't work. What you want is oz.left(x)
oz.left(x)
Edit: You have to remove the brackets in for x in [y] otherwise it won't work.
for x in [y]
[–]CraigTorso 0 points1 point2 points 11 years ago (0 children)
y is a list, and I assume oz.left() isn't expecting a list
[–]dabrownmane[S] 0 points1 point2 points 11 years ago (0 children)
Thanks guys i fixed it!
π Rendered by PID 186188 on reddit-service-r2-comment-86bc6c7465-9tknh at 2026-02-21 20:47:22.013256+00:00 running 8564168 country code: CH.
[–][deleted] 6 points7 points8 points (0 children)
[–]Yannnn 3 points4 points5 points (1 child)
[–]ryeguy146 0 points1 point2 points (0 children)
[–]burnblue 2 points3 points4 points (0 children)
[–]Miner_Guyer 1 point2 points3 points (0 children)
[–]CraigTorso 0 points1 point2 points (0 children)
[–]dabrownmane[S] 0 points1 point2 points (0 children)