python noob help

T

toyko

So yeah, I have this assignment for my computer science class,
http://pages.cpsc.ucalgary.ca/~boyd/231/as1.pdf so far this is what I have
wrote, any suggestions cause I am stuck!


xc, yc = input()
r = input()
x1, y1 = input()
x2, y2 = input()

a = (x2 - x1)**2 + (y2 - y1)**2
b = 2((x1 - xc)(x2 - x1) + (y1 - yc)(y2 - y1))
c = (x1 - xc)**2 + (y1 - yc)**2 - r**2

discrim = (b * b - 4 * a * c) ** 0.5
Q = (-b + discrim) / (2 * a)
Q = (-b - discrim) / (2 * a)

x = (1-Q) * x1 + Qx2
y = (1-Q) * y1 + Qx2

# CIRCLE
print "circle", xc, yc, r

# LINE
print "line", x1, y1, x2, y2
 
M

Marc 'BlackJack' Rintsch

So yeah, I have this assignment for my computer science class,
http://pages.cpsc.ucalgary.ca/~boyd/231/as1.pdf so far this is what I
have wrote, any suggestions cause I am stuck!

Learn Python and actually *think* about the problem and a solution. We
are not going to do your homework for you. You have to show a little
effort. So far you have just tried to copy the formulas from the
assignment to Python code -- and failed because there are runtime
errors. So you didn't even bother to test what you have so far before
crying for help.

Ciao,
Marc 'BlackJack' Rintsch
 
P

piloneur

Learn Python and actually *think* about the problem and a solution.  We
are not going to do your homework for you.  You have to show a little
effort.  So far you have just tried to copy the formulas from the
assignment to Python code -- and failed because there are runtime
errors.  So you didn't even bother to test what you have so far before
crying for help.

Ciao,
        Marc 'BlackJack' Rintsch


small hint :
"(5)(2)" don't work, use "5*2"
same for "Qx2", use "Q*2"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top