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?

Postby coatsoft » Fri Oct 04, 2013 8:43 pm

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 math
distance = 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) * distance
print ("The plane travelled " + (str(kilometresnorth)) + (" km north"))
kilometreseast = math.cos(degrees) * distance
print ("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?

Postby zeycus » Sat Oct 05, 2013 11:09 am

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.
Image

Live long and prosper.
Spock
User avatar
zeycus
 
Posts: 23
Joined: Sun Feb 17, 2013 10:30 am
Location: Madrid

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

Postby coatsoft » Sat Oct 05, 2013 12:56 pm

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?

Postby zeycus » Sun Oct 06, 2013 6:58 am

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.
Image

Live long and prosper.
Spock
User avatar
zeycus
 
Posts: 23
Joined: Sun Feb 17, 2013 10:30 am
Location: Madrid


Return to General Coding Help

Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 guests