Python Program for Unit Converter.

0


 
Phyton Program For Unit Converting. 


1.Phython Program for Convert Kilometers to Miles


Here's how it works:


The program asks the user to enter a value in kilometers, which is then stored in the variable kilometers.

The conversion factor from kilometers to miles is defined as conv_fac.

The program calculates the equivalent distance in miles by multiplying the number of kilometers by the conversion factor.

The result is then printed to the console, with the original value in kilometers and the converted value in miles displayed to two decimal places.

You can run this program in a Python interpreter or save it as a .py file and run it from the command line.


Input Program :


# take input from the user

kilometers = float(input("Enter value in kilometers: "))


# conversion factor

conv_fac = 0.621371


# calculate miles

miles = kilometers * conv_fac

print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))


Output of Program :

Enter value in kilometers: 50
50.00 kilometers is equal to 31.07 miles


2.Python Program for Convert Celsius to Fahrenheit

Here's how it works:

The program asks the user to enter a temperature in Celsius, which is then stored in the variable celsius.
The temperature in Fahrenheit is calculated using the formula (celsius * 1.8) + 32, and stored in the variable fahrenheit.
The program uses the format method to print the result to the console, with the original temperature in Celsius and the converted temperature in Fahrenheit displayed to one decimal place.
You can run this program in a Python interpreter or save it as a .py file and run it from the command line.

Input Program :

# take input from the user
celsius = float(input("Enter temperature in Celsius: "))

# calculate temperature in Fahrenheit
fahrenheit = (celsius * 1.8) + 32

# print the result
print('{:.1f} Celsius is equal to {:.1f} Fahrenheit'.format(celsius, fahrenheit))

Output of Program :

Enter temperature in Celsius: 50
50.0 Celsius is equal to 122.0 Fahrenheit

Post a Comment

0Comments
Post a Comment (0)