length_cm = input("Enter a length in centimeters: ")
# Check if the input is a valid positive number
if length_cm.isdigit() and int(length_cm) > 0:
# Convert the length to inches
length_inches = int(length_cm) / 2.54
# Print the result
print(f"{length_cm} centimeters is equal to {length_inches:.2f} inches.")
else:
print("Invalid entry. Please enter a positive number.")
The output of the program would depend on what the user enters as input. Here are some example outputs:
Input: 10
Output: 10 centimeters is equal to 3.94 inches.
Input: -5
Output: Invalid entry. Please enter a positive number.
Input: abc
Output: Invalid entry. Please enter a positive number.
0 Comments