Thursday, 27 June 2019

Python program to convert kilometers to miles Kilometer

The kilometer is a unit of length in the metric system. It is equivalent to 1000 meters.
Miles:

Mile is also the unit of length. It is equal to 1760 yards.

Conversion formula:

1 kilometer is equal to 0.62137 miles.

Miles = kilometer * 0.62137 
Kilometer = Miles / 0.62137 
See this example:

# Collect input from the user 
kilometers = float(input('How many kilometers?: ')) 
# conversion factor 
conv_fac = 0.621371 
# calculate miles 
miles = kilometers * conv_fac 
print('%0.3f kilometers is equal to %0.3f miles' %(kilometers,miles))

Tuesday, 11 June 2019

Python program to check if the input number is odd or even


# A number is even if division by 2 give a remainder of 0.
# If remainder is 1, it is odd number.

num = int(input("Enter a number: "))
if (num % 2) == 0:
   print("{0} is Even".format(num))
else:
   print("{0} is Odd".format(num))

Python program to find whether the number is positive and negative

num = float(input("Enter a number: "))
if num > 0:
   print("Positive number")
elif num == 0:
   print("Zero")
else:
   print("Negative number")