Question

In python using a def main() function, Write a function that will print a hello message,...

In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a while loop to make the program loop until the user enters 0 as an input. The program should then print a goodbye message.

Example run: Welcome to the program!

Please enter a number of inches to convert to feet: 32

32 inches is equal to 2.67 feet.

Please enter a number of inches to convert to feet: 60

60 inches is equal to 5.0 feet.

Please enter a number of inches to convert to feet: -20

Please enter a positive number: 40

40 inches is equal to 3.33 feet.

Please enter a number of inches to convert to feet: 0

Have a nice day!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def hello():
    print("Welcome to the program!")


def main():
    hello()
    while True:
        inches = int(input("Please enter a number of inches to convert to feet: "))
        while inches < 0:
            inches = int(input("Please enter a positive number: "))
        if inches == 0:
            break
        print("{} inches is equal to {:.2f} feet.".format(inches, inches / 12))
    print("Have a nice day!")


main()




Add a comment
Know the answer?
Add Answer to:
In python using a def main() function, Write a function that will print a hello message,...
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
  • 1. In Python, Write a function to convert inches into yards, feet and inches. The functions...

    1. In Python, Write a function to convert inches into yards, feet and inches. The functions should take one parameter, 'inches', and print out the number of yards, feet, and inches equivalent to the value of the argument. Call the function after prompting the user to enter the number of inches. Don't forget to convert the input to an 'int'. 2. In Python,Write a function to convert celsius to fahrenheit. The function should return a value, which you should assign...

  • This is in python. I need to print out a specific message depending on the number...

    This is in python. I need to print out a specific message depending on the number that's input. for example, if the user inputs 1, program should print out "hello". if the user inputs 2, program should print out "hi". But also the program should keep asking for a number to be input after a valid number is input. For example, user inputs 1, program prints out "hello" and then asks the user to input another value. but also the...

  • p1 p2 in p2 there is a typo, if grade <0 or grade >100: should be...

    p1 p2 in p2 there is a typo, if grade <0 or grade >100: should be if percent <0 or percent > 100: Write a program to compute a person's height & print out a message. The user will input feet and inches. The program will convert that to inches, and then print a message, based on the total inches. If the total inches is greater than 72, the message should be something like, "You're tall." If the total inches...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • 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...

  • Write python program using IDLE Write a full program that asks the user to enter his/her...

    Write python program using IDLE Write a full program that asks the user to enter his/her name then repeatedly ask to enter the temperature in Fahrenheit and convert it to Celsius, the program should then prompt the user if he/she wants to continue or exit the program. The formula for the conversion is: °C = (°F - 32) x 5/9 The program should use a function for the conversion. An Example of a sample run should appear on the screen...

  • please write c programming for this code below. Write a program to print a pattern of...

    please write c programming for this code below. Write a program to print a pattern of numbers separated by spaces for the given number of rows. At the time of execution, the program should print the message on the console as: Enter number of rows For example, if the user gives the input as: Enter number of rows : 4 then the program should print the result as: 232 34543 4567654

  • Ask the user to enter a message Ask the user how many time they want to...

    Ask the user to enter a message Ask the user how many time they want to print the message Then use "while","do-while" and "for" loop to print the message. Show the number at the beginning of the lines when printing. For example: Enter your message: Welcome to Java How many time you want to print this message: 3 Using "while" loop: 1=> Welcome to Java 2=> Welcome to Java 3=> Welcome to Java Using "do-while" loop: 1=> Welcome to Java...

  • # convert.py # A program to convert Celsius temps to Fahrenheit # by: Susan Computewell def...

    # convert.py # A program to convert Celsius temps to Fahrenheit # by: Susan Computewell def main(): celsius = eval(input("What is the Celsius temperature? ")) fahrenheit = 9/5 * celsius + 32 print("The temperature is", fahrenheit, "degrees Fahrenheit.") main() PORTION ONE: Based the convert.py, so it can convert temperatures from Fahrenheit to Celsius, instead of original Celsius to Fahrenheit. Make sure to change the message to reflect the change of introduction and final result. Name it as: convert_v2.py. Run it...

  • write in python idle Write full program that asks the user to enter his/her name then...

    write in python idle Write full program that asks the user to enter his/her name then repeatedly ask to enter the temperature in Fahrenheit and convert it to Celsius, the program should then prompt the user if he/she wants to continue or exit the program. The formula for conversion is: °C = (°F - 32) x 5/9 The program should use a function for the conversion. An Example of a sample run should appear on the screen like the text...

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