212k views
3 votes
Write code that computes and prints the height of a person in feet and inches using the format shown below (with each xxx replaced with the appropriate value). That person is xxx feet and xxx inches tall. Assume the person's total height in inches (such as 70) is already stored as an integer in a variable named height. so if it's 70 inches then it's 5 feet 10 inches

1 Answer

4 votes

Final answer:

To calculate a person's height in feet and inches from a height in inches, integer division and modulus are used to obtain the feet and the remaining inches, which can then be formatted into a string and printed.

Step-by-step explanation:

To compute and print the height of a person in feet and inches using the provided format, you can use the following Python code as an example:

height = 70 # Replace 70 with the actual height in inches
feet = height // 12
inches = height % 12
print(f'That person is {feet} feet and {inches} inches tall.')

This code snippet stores the total height in inches in a variable named height. It computes the number of feet by performing integer division (//) by 12, and the remaining inches by the modulus operator (%) which finds the remainder.

User Mukesh Soni
by
7.3k points