This class just keeps getting worse. My next lab he had us do is this, "Write a program that computes the intersection of a circle with a horizontal line and displays the information textually and graphically".

He gave us absolutely no help or anything to do this. He just said do it. How in the heck are we supposed to do this without any help? I don't think he understands this is a** INTRO** class... I am going to just jump in on this project, any/all help would be much appreciated and loved..

Thanks for the help on my last post guys also.

Recommended Answers

All 15 Replies

A circle with center (a,b) and radius r has the equation (x-a)^2 +(y-b)^2=r^2. If the horizontal line has the equation y = c, it means that the intersection points are given by (x-a)^2 = r^2 - (c-b)^2 when this is non negative, so that

x = a +/- sqrt(r**2 - (b-c)**2)
y = c

You could ask the user to enter the center, radius and the number c.

Wow... I know none of that stuff. He just gave us that problem and that's it. I have been reading some codes in my book that are similar, but have yet to do anything that really matters...

You want to write that part out in code for me?? Lol

We first want to admire your code ;)

KY_Fan no one will do the actual homework/lab asignment for you, but, we can help you.
As pyTony said, let's see what you did by now related to this lab asignment. Use what Gribouillis said regardless the equations of a circle which intersects a line.
Also, for the graphical part, you can use the turtle module from python: See more here.
As for the console part, that's easy, if you apply the formulae, you just have to print out the answers.
So, start working on your project, and when you hit a "dead end" just post the question, the part of the code which gives you headaches, the error, and we'll try to help you.
Good luck now in solving this lab asignment.

commented: well said +10
commented: Good tone of response +12

I understand that you all won't do the assignment for me but the problem I had was that I didn't have any idea on how to start it... So I just went and talked to my old High School teacher and let him show me some stuff.

I bet if people started paying you guys then you would love to do the HW assignments!! Lol

I finally wrote my own code that should work (with help from a friend). The only problem is I keep getting an error message and he won't tell me why lol. He wants me to figure it out, which I figured out one error but can't the next.

def average(a,b,c):
    avr=(a+b+c)/3.0
    return avr

def main():
    a1,b1,c1=eval(input("Please enter any three numbers: "))
    avr1=average(a,b,c)
    print ('the average of these numbers =', avr)

main()

I get an error saying, (TypeError: 'int' object is not iterable). I think it is for the line with the input.

Did you enter comma between numbers? Using full eval for the purpose is bad idea. Input numbers one by one and use float instead.

Lol I did what you said and it worked (Using commas). Then I get another error on the next line saying a is not defined. When the fall semester begins I am def going to take the classes IN CLASS, instead of online. I will probably even try to find a different professor.

Of course it is not, where you see it defined? Nowhere is any variable named a except in that line in function main (avarage definition's parameters of course do not matter as they are local to the function)

I change the code little,to how i think it should look.
Ask if you dont understand it.

def average(a,b,c):
    avr = (a+b+c) / 3.0
    return avr

def main():
    user_input = input("Please enter any three numbers: ")
    numbers = [float(i) for i in user_input]
    avr = average(numbers[0],numbers[1],numbers[2])
    print('The average of these numbers = {}'.format(avr))

main()

And to make it also work with Python3 and any number of numbers entered:

#Python 2
from __future__ import print_function, division

try:
    input, range = raw_input, xrange
except:
    pass

#all
def average(*nums):
    return sum(nums) / len(nums)

def main():
    numbers = [float(i) for i in input("Please enter any number of numbers separated by comma: ").split(',')]
    avr = average(*numbers)
    print('The average of these {} numbers = {}'.format(len(numbers), avr))

main()

Thanks guys. I kind of understand whats going on now!

PyTony, do you work as a programmer or what?

I bet if people started paying you guys then you would love to do the HW assignments!

Don't push it.
Now you saw a couple of examples. Try to figure out why does these 2 codes work, and yours doesn't. It's better to learn why doing things in a specific way is better than doing things in another way. And about that homework thing, I personally won't make your homework for you, even if you'd pay me. It wouldn't help you a bit (talking from the programming perspective). You see, our goal here is no to be pricky or cocky to other people, but rather to help them learn either from their mistakes or from given materials or explanations.
I hope now that you understood my point here. And talking to other friends/teachers is good, as for this:

The only problem is I keep getting an error message and he won't tell me why.

you know now why he did that.

You all are a great and awesome help. I'm really glad that you guys are so open to help people that don't quiet understand programming. It is a really good thing. Also, looking at the working code helps me see some differently than just looking at my messed up code also.lol

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.