## can someone tell me what is wrong with this?

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

### can someone tell me what is wrong with this?

For certain numbers (eg. 20 distance and 60 distance) that are input it comes out as the distance of north and west as minus numbers but this is not right. You will need to know your trigonometry for this one.
Code: Select all
`import mathdistance = float(input("Please enter in kilometres the distance that the plane traveled"))degrees = float(input("Please enter in how many degrees north the plane travelled"))kilometresnorth = math.sin(degrees) * distanceprint ("The plane travelled " + (str(kilometresnorth)) + (" km north"))kilometreseast = math.cos(degrees) * distanceprint ("The plane travelled " + (str(kilometreseast)) + (" km east"))`
coatsoft

Posts: 7
Joined: Fri Oct 04, 2013 8:40 pm

### Re: can someone tell me what is wrong with this?

You should be more precise with your question. What is what you find wrong here? Do you know the right answer?

Anyway, at first sight one thing is clearly wrong: you ask the user to enter an angle in degrees. But you use it, without any transformation, as parameter for math.sin and math.cos. But those require angles in radians. You should convert degrees to radians.

Live long and prosper.
Spock

zeycus

Posts: 23
Joined: Sun Feb 17, 2013 10:30 am

### Re: can someone tell me what is wrong with this?

zeycus wrote:You should be more precise with your question. What is what you find wrong here? Do you know the right answer?

Anyway, at first sight one thing is clearly wrong: you ask the user to enter an angle in degrees. But you use it, without any transformation, as parameter for math.sin and math.cos. But those require angles in radians. You should convert degrees to radians.

Ok thanks for your help. I have kind of taught myself the math functions as my teacher just posted tasks online but did not explain it in class.
coatsoft

Posts: 7
Joined: Fri Oct 04, 2013 8:40 pm

### Re: can someone tell me what is wrong with this?

coatsoft wrote:Ok thanks for your help. I have kind of taught myself the math functions as my teacher just posted tasks online but did not explain it in class.

Then you are doing a good job. About the degree/radian issue, be aware that trigonometric functions in pretty much every programming language use radians. Python is (fortunately!) no exception.

Live long and prosper.
Spock

zeycus

Posts: 23
Joined: Sun Feb 17, 2013 10:30 am