Python

Python program to enter the length in centimeter and convert it into meter and kilometer1 min read

Python program to enter the length in centimeter and convert it into meter and kilometer. There are you will learn how to convert the centimeter into meter and kilometer in Python language.

Q: Write a program to Enter length in centimeters and convert it into meter and kilometer

Formula:

`1m = 100cm`

`1km = 100000cm`

Write a program to convert kilometers to meters in Python

Output:

What happend in this code:

1. The first line `print("Enter the length in centimeter::")` is used to prompt the user to enter a length in centimeter.
2. The line `c, m, k = float(input()), 0, 0` is used to take the input from the user and store it in a variable `c`, and initialize variables `m` and `k` to 0.
3. The line `m = (float)(c / 100)` converts the length in centimeter to meter by dividing it by 100, and storing the result in the `m` variable.
4. The line `k = (float)(c / 100000)` converts the length in centimeter to kilometer by dividing it by 100,000, and storing the result in the `k` variable.
5. Finally, the lines `print("Length in Meter = ", m, " meter")` and `print("Length in Kilometer = ", k, " kilometer")` are used to print the length in meter and kilometer, respectively.

That’s it! This simple program takes a length in centimeter as input from the user and converts it into meter and kilometer.