Answer:
This example is implemented in Python 3:
fft = input("How many feet for Fabric A? ")
fin = input("How many inches for Fabric A? ")
sft = input("How many feet for Fabric B? ")
sin = input("How many inches for Fabric B? ")
print("Length for Fabric A is:", fft, "feet and", fin, "inches")
print("Length for Fabric B is:", sft, "feet and", sin, "inches")
INPUT:
How many feet for Fabric A? 5
How many inches for Fabric A? 5
How many feet for Fabric B? 1
How many inches for Fabric B? 1
OUTPUT:
Length for Fabric A is: 5 feet and 5 inches
Length for Fabric B is: 1 feet and 1 inches
Explanation:
To begin, define variables as follows:
- fft - represents the first fabric's feet
- fin - represents the first fabric's inches
- sft - represents the second fabric's feet
- sin - represents the second fabric's inches
Then, prompt the user for input using:
This function allows a prompt within the parentheses to guide user input. For example, "How many feet for Fabric A?"
After gathering the input, output the lengths of Fabrics A and B.
- print("TEXT HERE") - used for displaying a string. For numbers or variables, avoid surrounding them with quotes.
What if you want to combine strings and variables in one print statement?
Use this syntax:
- print("TEXT HERE", VARIABLE)
This merges the text and the variable within a single print call by placing a comma after the string.
Repeat this format to compose an entire sentence:
- print("TEXT 1:", VARIABLE1, "TEXT 2", VARIABLE2)
Important Note:
To perform arithmetic operations (+, -, *, /, %) on inputs, convert them to integers or floats. For example:
- fft = input("How many feet for Fabric A? ") - this input is a string.
- fft = int(input("How many feet for Fabric A? ")) - wrapping input() inside int() converts it to an integer. Alternatively, use float() if needed.
- Once converted, you can apply addition, subtraction, multiplication, and division on the variables.