Help with specific homework problem in Python 3.2

This is the place for queries that don't fit in any of the other categories.

Help with specific homework problem in Python 3.2

Postby devin79 » Sun Sep 22, 2013 8:53 pm

Ok, So apparently over at "overstack" they get their panties in a bunch, if a college student, with ZERO programming skills asks a question, that they find simplistic. Then they throw a hissy fit and don't help you. I am hoping this forum is different. I am a college student majoring in a program sponsored by Sony Imageworks, that teaches students how to produce and create CGI effects for film and/or videogames. I wish to work on films. I am very good with software like Maya, 3DS MAX, Houdini, NUKE, etc...but they just instituted a "intro to Python" class this semester and as a beginning Sophomore I am required to take it. I am struggling in the class and am doing my best to get these assignments done, but I do need a little help, and I would hope that I do not encounter the same resistance here that I did from the "elitists" over at "overstack"

I am trying to do part 1 of a code for the Lindenmayer System. We need to code letters and symbols to make them into turtle commands. I have a code that is pretty good I think, but I am running into a specific stumbling block. When I run the program it gives me an error on my "pencolor" RGB inputs. Here is my code as it stands now.

code:
import turtle
command = str(input("enter a command line"))
length = int(input("enter a length"))
angle = float(input("enter an angle"))

commandLength = len(command)
for i in range(commandLength):
if(command[i] == 'h'):
turtle.forward(length)
elif(command[i] == 'f'):
turtle.forward(length)
elif(command[i] == 'g'):
turtle.penup()
elif(command[i] == '+'):
turtle.right(angle)
elif(command[i] == '-'):
turtle.left(angle)
elif(command[i] == 'a'):
turtle.pencolor(0, 0, 255) "supposed to be blue"
elif(command[i] == 'b'):
turtle.pencolor(255, 0, 0) "supposed to be red"
elif(command[i] == 'c'):
turtle.pencolor(0, 255, 0) "supposed to be green"
elif(command[i] == 'd'):
turtle.pencolor(255, 255, 0) "supposed to be yellow"
elif(command[i] == 'e'):
turtle.pencolor(255, 0, 255) "supposed to be pink"
elif(command[i] == 'f'):
turtle.pencolor(0, 0, 0) "supposed to be black"

So if I run the program I get a box that says "enter a command line"...I enter h+a: Then it says "enter a length"...I say 20: then it says "enter an angle"...I say 90
at this point I get the following error. "TurtleGraphicsError" "bad color sequence:(0, 0, 255)

I got the turtle commands from a website that specifically gives you turtle commands, and this is how they said to do it...Could someone give me some help on why this error is occurring, the project is due tonight and I would really appreciate the help, and please remember I am totally new to this stuff and am doing my best to google and come up with the solutions on my own. Thank You.
devin79
 
Posts: 10
Joined: Mon Sep 16, 2013 10:51 pm

Re: Help with specific homework problem in Python 3.2

Postby dboxall123 » Sun Sep 22, 2013 9:18 pm

Hi mate. Ha, I know what you mean, they are a grumpy lot over their aren't they? Everyone is quite friendly here though. I'm not that familiar with turtle graphics, but where you write
Code: Select all
turtle.pencolor(0,0,255)
should it not be
Code: Select all
turtle.pencolor = (0,0,255)
Try it post back if you have any other problems mate :D
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Help with specific homework problem in Python 3.2

Postby devin79 » Sun Sep 22, 2013 9:27 pm

Actually...That did get rid of the error, unfortunately I am not getting any color on my turtle. Thanks for your help though, I do appreciate it:)
devin79
 
Posts: 10
Joined: Mon Sep 16, 2013 10:51 pm

Re: Help with specific homework problem in Python 3.2

Postby stranac » Sun Sep 22, 2013 9:32 pm

You were already warned about code tags.
I suggest you read this, or I will start deleting your messages without further warning.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1093
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help with specific homework problem in Python 3.2

Postby dboxall123 » Sun Sep 22, 2013 9:32 pm

I'm not 100% sure what you are trying to acheive here to be honest. If you repost your code, but this time highlight it and put it inside code blocks, and give me a full explanation of what you are trying to do, I'll see if I can help.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Help with specific homework problem in Python 3.2

Postby devin79 » Sun Sep 22, 2013 9:54 pm

Sorry, I was unaware of the "codetag"...I am new here, and I wasn't aware I was warned...so maybe you should calm down a bit.

I am trying to convert the letters A,B,C,D,E,F. into colors for my turtle to draw. H has been converted to the command turtle.forward(length)
So A,B,C,D,E,F. need to be converted into pencolor commands, so that when I write H+A...it draws forward by however much length I put in, and it draws in blue.

here is my code again.

Code: Select all
import turtle
command = str(input("enter a  command line"))
length = int(input("enter a length"))
angle = float(input("enter an angle"))

commandLength = len(command)
for i in range(commandLength):
    if(command[i] == 'h'):
        turtle.forward(length)
    elif(command[i] == 'f'):
        turtle.forward(length)
    elif(command[i] == 'g'):
        turtle.penup()
    elif(command[i] == '+'):
        turtle.right(angle)
    elif(command[i] == '-'):
        turtle.left(angle)
        colormode()
        1.0
    elif(command[i] == 'a'):
        turtle.pencolor =(0, 0, 255)
    elif(command[i] == 'b'):
        turtle.pencolor = (255, 0 ,0)
    elif(command[i] == 'c'):
        turtle.pencolor = (0, 255, 0)
    elif(command[i] == 'd'):
        turtle.pencolor = (255, 255, 0)
    elif(command[i] == 'e'):
        turtle.pencolor = (255, 0, 255)
    elif(command[i] == 'f'):
        turtle.pencolor = (0, 0, 0)
 


I think I did the code thing right, if not please just let me know...I am trying to follow the rules as best I can.
devin79
 
Posts: 10
Joined: Mon Sep 16, 2013 10:51 pm

Re: Help with specific homework problem in Python 3.2

Postby dboxall123 » Sun Sep 22, 2013 10:00 pm

Maybe I should calm down a bit? I never got angry! I merely suggested that you should add code tags, it makes it easier for us to read and test. I think you should re-evaluate your attitude, I am trying to help you. Anyways, repost your code again, but this time copy and paste the code, highlight the code and then press the code tag. This will make the code appear in a box and it will keep all of the indentations so that I can copy and paste it directly into IDLE to test it.

Edit - ah, you've alreaady done it :D
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Help with specific homework problem in Python 3.2

Postby devin79 » Sun Sep 22, 2013 10:07 pm

Sorry dboxall123...I wasn't talking to you. I appreciate you trying to help me. I was actually addressing the moderator not you....sorry for the confusion.

Ok, So I am trying to do this in pyscripter, if that makes any difference. Here is my code once again. I will box it and try to highlight it:)

Code: Select all
import turtle
command = str(input("enter a  command line"))
length = int(input("enter a length"))
angle = float(input("enter an angle"))

commandLength = len(command)
for i in range(commandLength):
    if(command[i] == 'h'):
        turtle.forward(length)
    elif(command[i] == 'f'):
        turtle.forward(length)
    elif(command[i] == 'g'):
        turtle.penup()
    elif(command[i] == '+'):
        turtle.right(angle)
    elif(command[i] == '-'):
        turtle.left(angle)
        colormode()
        1.0
    elif(command[i] == 'a'):
        turtle.pencolor =(0, 0, 255)...Supposed to be Blue
    elif(command[i] == 'b'):
        turtle.pencolor = (255, 0 ,0)...Supposed to be red
    elif(command[i] == 'c'):
        turtle.pencolor = (0, 255, 0)...Supposed to be green
    elif(command[i] == 'd'):
        turtle.pencolor = (255, 255, 0)...Supposed to be yellow
    elif(command[i] == 'e'):
        turtle.pencolor = (255, 0, 255)...Supposed to be pink
    elif(command[i] == 'f'):
        turtle.pencolor = (0, 0, 0)...supposed to be black
devin79
 
Posts: 10
Joined: Mon Sep 16, 2013 10:51 pm

Re: Help with specific homework problem in Python 3.2

Postby devin79 » Sun Sep 22, 2013 10:15 pm

One more thing...My TA (teachers Assistant) says this. Pencolor can't be above 1 or less than 0. Not the 255 stuff that ur doing. So it's like (1, .5, .2)

Does that help?
devin79
 
Posts: 10
Joined: Mon Sep 16, 2013 10:51 pm

Re: Help with specific homework problem in Python 3.2

Postby dboxall123 » Sun Sep 22, 2013 10:21 pm

Right,well I'm working at it at the moment, you'll have to bear with me though because I'm learning this as I go. I do have a couple of questions though.
1 - You've set both 'h' and 'f' to move the turtle forward. Is this intentional, or is one of them supposed to go backward?
2 - The colours that I am using are in the RGB colour scale. So does he/she mean that you should only be using colours with 0-9 red, 0-9 green and 0-9 blue?
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Help with specific homework problem in Python 3.2

Postby devin79 » Sun Sep 22, 2013 10:43 pm

Yes, Both H and F are supposed to be the same. Let me post the actual assignment to try and help you out.

Assignment:

Character Draw Commands
h
Draw a straight line segment length pixels long in the current
heading.
f Same as h
g
Move, without drawing, a straight line segment length pixels
long in the current heading.
+ Turn the heading clockwise by angle.
- Turn the heading counter-clockwise by angle.
A
Each of these color commands must change the turtle color to
color that is different form the background and different from
the other 5 color commands. Pick colors that you think look good
together.
B
C
D
E
F
Any other
character
Ignore

So, I am stuck on the pencolor deal. I am trying to make Red, Blue, Green, Yellow, Orange, and black. So far I have figured out Blue (0.0, 0.0, 1.0)...this one works.
also the one my TA gave me...(1, .5, .2) (Red)...this one works

Do you know how to make the other colors in RGB in the way my TA. said...."Pencolor can't be above 1 or less than 0."

If I can do that I think the assignment will be complete:)
devin79
 
Posts: 10
Joined: Mon Sep 16, 2013 10:51 pm

Re: Help with specific homework problem in Python 3.2

Postby dboxall123 » Sun Sep 22, 2013 11:06 pm

Ok, this appears to be in order.
Code: Select all
import turtle
wn = turtle.Screen()
turt = turtle.Turtle()

command = input('enter a command line')
length = int(input('enter a length'))
angle = float(input('enter an angle'))


for i in command:
    if i == 'h':
        turt.forward(length)
    elif i == 'f':
        turt.forward(length)
    elif i == 'g':
        turt.penup()
    elif i == 'k':
        turt.pendown()
    elif i == '+':
        turt.right(angle)
    elif i == '-':
        turt.left(angle)
    elif i == 'A':
        turt.color(0.0,0.0,0.1)
    elif i == 'B':
        turt.color('red')
    elif i == 'C':
        turt.color('green')
    elif i == 'D':
        turt.color('lightblue')
    elif i == 'E':
        turt.color('lightred')
    elif i == 'F':
        turt.pencolor('lightgreen')
I'm not entirely sure about the colour system that;'s being used here, but I have found that you can specify colours by typing 'green' ,'red', etc, so you will have to mess around with the colours a bit, but I think this is what your tutor is looking for. Also, I've taken the liberty of adding a pendown() command, because if you lift the pen up it no longer shows anything until you specify to put the pen back down. Anyways, play around with it and see if it works.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Help with specific homework problem in Python 3.2

Postby stranac » Sun Sep 22, 2013 11:11 pm

dboxall123:
I believe he was speaking to this angry admin(not moderator).

devin79:
mic told you to use code tags in a nice way.
That didn't work, so I decided to use a bit sharper words. And look, it worked.

The TA wrote:"Pencolor can't be above 1 or less than 0."

That is not entirely correct.
You can use turtle.colormode(), and then be able to use values up to 255.
But using values up to 1.0 is just as simple, you just divide every value by 255...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1093
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help with specific homework problem in Python 3.2

Postby devin79 » Sun Sep 22, 2013 11:16 pm

Ok, Thanks. I managed to figure out how to get all the colors I need. Sorry about the Code thing, I wasn't aware anyone had said anything, and I didn't understand that part of the forum. Now I know:)

Thank You for your help:)
devin79
 
Posts: 10
Joined: Mon Sep 16, 2013 10:51 pm

Re: Help with specific homework problem in Python 3.2

Postby dboxall123 » Sun Sep 22, 2013 11:22 pm

Stranac:
Lol, I hadn't actually seen your post when I posted my reply :D

devin69:
Is this all working ok? Kind of enjoyed turtle, I think I'm gonna work through the entire tutorial now :D
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Help with specific homework problem in Python 3.2

Postby micseydel » Mon Sep 23, 2013 4:11 am

devin79 wrote:Sorry, I was unaware of the "codetag"...I am new here, and I wasn't aware I was warned...so maybe you should calm down a bit.

viewtopic.php?f=6&t=6949&p=8753#p8803
micseydel wrote:Please post working Python code in code tags even if it doesn't quite solve the problem
(emphasis added)

But you didn't respond to my post, so maybe you didn't see that. Anyway, hacker culture is extremely forgiving but very intolerant of people not following directions (especially those that benefit everyone).
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1220
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests