Respuesta :
Answer:
This is written using 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:
First is to declare the variables:
- fft - stands for First Feet
- fin - stands for First Inches
- sft - stands for Second Feet
- sin - stands for Second Inches
Then we ask the user to input a value by using:
- input()
By using this, you can add a label inside ( and ) to provide guidance to the user. As such, I wrote "How many feet for Fabric A?"
After which, we print the answers for Fabric A and B.
- print("TEXT HERE") - this is the simplest way to print a string. If you want to print an integer or variables, you don't have to include the quotation marks.
But what if you want to print both string and variables on the same line?
In which case, you can write it this way:
- print("TEXT HERE", VARIABLE)
What this does is it concatenates the string and the variable in one go. After the quotation marks, simply add a comma right after. There are other ways of doing this but this is the most straightforward answer.
Now, repeat the process to print the entire sentence:
- print("TEXT 1:", VARIABLE1, "TEXT 2", VARIABLE2)
Important Note:
If you need to do calculations (+, *, /, -, %) it is important to convert the inputs into integers or floats. Using the answer above:
- fft = input("How many feet for Fabric A? ") - the value entered here is only considered as a string.
- fft = int(input("How many feet for Fabric A? ") ) - meanwhile, by enclosing input() inside int(), this effectively becomes an integer. You may also use float() when necessary.
- In which case, you can add, subtract, multiply, and divide the variables.
Answer:
ft1= int(input("Enter the Feet: "))
in1= int(input("Enter the Inches: "))
ft2= int(input("Enter the Feet: "))
in2= int(input("Enter the Inches: "))
totalft= ft1 + ft2 + int((in1+in2)/12)
totalin= (in1+in2) % 12
print("Feet: " + str(totalft) + " Inches: " + str(totalin))