nki
nki

Reputation: 21

I cant figure out why my python code isn't returning the answer in miles

Write a program that takes as input a number of kilometers and prints the corresponding number of nautical miles. Use the following approximations:

• A kilometer represents 1/10,000 of the distance between the North Pole and the equator.

• There are 90 degrees, containing 60 minutes of arc each, between the North Pole and the equator.

• A nautical mile is 1 minute of an arc.

That is the statement that I have to flow in python.

This is the program that I have written down but it's only showing the kilometers.

Kilometers=input("Enter the amount of kilometers:")

degreesPerMin = 90*60

onekilo = degreesPerMin/10,000

nauticalmile = onekilo*Kilometers

print =input("Kilometers,is,nauticalmile,Nautical miles")

Upvotes: 0

Views: 4113

Answers (2)

Tharu
Tharu

Reputation: 330

When you are going to take an input you should first declare the data type (eg: int,str,float) if not the data type of the input is set to str/String by default.

If you want to the get the output of the equations/variables you declared (eg: degreesPerMin = 90*60, etc.), you don't have to write them inside brackets because you only use brackets to print Strings or characters.

Kilometers=int(input("Enter the amount of kilometers:"))#datatype is declared(int)

degreesPerMin = 90*60

onekilo = degreesPerMin/10000

nauticalmile = onekilo*Kilometers

print("Kilometers =",Kilometers)#the variable name shouldn't be inside brackets(Kilometers)

print("degreesPerMin =",degreesPerMin)

print("onekilo =",onekilo)

print("nauticalmile =",nauticalmile)

Upvotes: 0

Joe Ferndz
Joe Ferndz

Reputation: 8508

You have a few minor errors in your code that needs to be fixed.

  1. Your input statement has to be converted into an int before you use it for computation nauticalmile = onekilo*Kilometers

  2. Your division statement has a comma. Python will consider comma as another variable. So remove the comma onekilo = degreesPerMin/10,000 in this statement

  3. Your print statement needs to be updated. Don't use input statement in your print statement when you want to just display information. Also, separate out strings and variables with proper quotes. print =input("Kilometers,is,nauticalmile,Nautical miles") needs to be edited to print (Kilometers,"is",nauticalmile,"Nautical miles")

When these changes are made, your program works perfectly. See below updated code.

Kilometers=int(input("Enter the amount of kilometers:"))

degreesPerMin = 90*60

onekilo = degreesPerMin/10000

nauticalmile = onekilo*Kilometers

print (Kilometers,"is",nauticalmile,"Nautical miles")

Output:

Enter the amount of kilometers:200
200 is 108.0 Nautical miles

Upvotes: 2

Related Questions