Question

Write a program that prompts the user to enter a length in feet and inches and...

Write a program that prompts the user to enter a length in feet and inches and outputs the equivalent length in centimeters. If the user enters a negative number or a nondigit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Using Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1
feet = input("Enter feet: ")
if(not feet.isnumeric()):
    print("Input should be a positive number")
else:
    feet = float(feet)
    if(feet < 0):
        print("Input should be a positive number")
    else:
        inch = input("Enter inch: ")
        if (not inch.isnumeric()):
            print("Input should be a positive number")
        else:
            inch = float(inch)
            if (inch < 0):
                print("Input should be a positive number")
            cm = feet*30.48 + inch*2.54
            print("Centimeters:",cm)

Add a comment
Know the answer?
Add Answer to:
Write a program that prompts the user to enter a length in feet and inches and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • Write program that prompts the user to enter a person's date of birth in numeric form...

    Write program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle...

  • Write a program that prompts the user to enter a person's birth date in numeric form...

    Write a program that prompts the user to enter a person's birth date in numeric form (e.g. 8-27-1980) and outputs the date of birth in the format of month day, year (e.g. August 27, 1980). Your program must work for three types of exceptions - invalid day, invalid month and invalid year (year must be between 1915 and 2015). Make these as class driven exceptions. Use one try-catch block with separate catches for the exception classes to handle errors for...

  • Python Programming 4th Edition: Write a program that asks the user for the number of feet....

    Python Programming 4th Edition: Write a program that asks the user for the number of feet. The program converts those feet to inches by using the formula ’12 * feet’. Hint: Define main () program Get the number of feet from the user Define variables Call a function feet_to_inches(feet) The function receives the number of feet and returns the number of inches in that many feet. The output should look like as follows: Enter the number of feet: If the...

  • 1) Write a Python program that prompts the user to enter the current month name and...

    1) Write a Python program that prompts the user to enter the current month name and prints the season for that month. Hint: If the user enters March, the output should be "Spring"; if the user enters June, the output should be "Summer". 2 )Write a Python program using the recursive/loop structure to print out an equilateral triangle below (double spacing and one space between any two adjacent asterisks in the same row).          *      * * * *...

  • Write a program that prompts the user to enter the sides and their length of a...

    Write a program that prompts the user to enter the sides and their length of a regular polygon and display its area. ****Using c++

  • Write a C++ program that prompts the user to enter two numbers. Then prompt the user...

    Write a C++ program that prompts the user to enter two numbers. Then prompt the user to select from the following options: a. Add the numbers. b. Multiply the numbers. c. Terminate the program Use the appropriate control structures (loops, if else, switch-case, etc) to make your program as short and efficient as possible. Minor syntax errors are forgiven in this exercise; just focus on the correct structure, declarations and sequence of instructions

  • Write java program that prompts the user to enter integers from the keyboard one at a...

    Write java program that prompts the user to enter integers from the keyboard one at a time. Program stops reading integers once the user enters the same value three times consecutively. Program then outputs "Same entered 3 in a row. "

  • Write a program that prompts the user for a string and stores the user's string into...

    Write a program that prompts the user for a string and stores the user's string into a variable using getline(). After receiving the string, the program counts and displays the number of vowels in the string. Then, the program should prompt the user if they would like to enter another string.

  • Design a Python program that prompts the user to enter "yes" or "no" and validates the...

    Design a Python program that prompts the user to enter "yes" or "no" and validates the input. (Use a case-insensitive comparison) and another Python program that prompts the user to enter a number in the range of 1 through 100 and validates the input

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT