In: Computer Science
Instructions from your teacher:
Write a Python program that does the following:
Displays a welcome message
Prompts a user to enter a number (an integer), and then converts that value from inches to feet. If the user entered a negative number, display an error message telling the user that it was not a "positive " number and prompt the user to enter a number again.
Displays the converted value, then " feet"
Continue converting the user's valid values until the user enters 0. Your program should then display a goodbye message.
Example 1:
Welcome to my inches to feet converter!
Please enter a number of inches: 32
2.7 feet
Please enter a number of inches: 60
5.0 feet
Please enter a number of inches: -20
Please enter a positive number!
Please enter a number of inches: 40
3.3 feet
Please enter a number of inches: 0
Have a nice day!
Example 2:
Welcome to my inches to feet converter!
Please enter a number of inches: -32
Please enter a positive number!
Please enter a number of inches: -21
Please enter a positive number!
Please enter a number of inches: -10
Please enter a positive number!
Please enter a number of inches: 0
Have a nice day!
Python code:
#printing Welcome message
print("Welcome to my inches to feet converter!")
#accepting number of inches
inch=int(input("Please enter a number of inches: "))
#looping till inch is 0
while(inch!=0):
#checking if inch is greater than 0
if(inch>0):
#printing feet rounded
to 1 decimal
print(str(round(inch/12,1))+" feet")
else:
#asking to enter
positive number
print("Please enter a
positive number!")
#accepting number of inches
inch=int(input("Please enter a number of inches:
"))
#printing goodbye message
print("Have a nice day!")
Screenshot:
Input and Output: