Reputation: 21
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
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
Reputation: 8508
You have a few minor errors in your code that needs to be fixed.
Your input statement has to be converted into an int before you use it for computation nauticalmile = onekilo*Kilometers
Your division statement has a comma. Python will consider comma as another variable. So remove the comma onekilo = degreesPerMin/10,000
in this statement
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