Skip to content
← Back to Community
Edhesive Computer Science 2.3 Help!
Profile icon
linda231

The language used is Python and the question asks - Write a program that inputs the length of two pieces of fabric in feet and inches (as whole numbers) and prints the total.
Enter the Feet for the first piece of fabric: 3
Enter the Inches for the first piece of fabric: 11
Enter the Feet for the second piece of fabric: 2
Enter the Inches for the second piece of fabric: 5
It displays:
Feet: 6 Inches: 4

So far I have this:
x=float(input("Enter the Feet for the first piece of fabric:"))
y=float (input("Enter the Inches for the first piece of fabric:"))
j=float (input("Enter the Feet for the second piece of fabric:"))
k=float (input("Enter the Inches for the second piece of fabric:"))
print ("Total: "+str((x+j%(k+y))
And it just ain't working
Can someone help?

Answered by heyitsmarcus [earned 5 cycles]
View Answer
Voters
Profile icon
ANGELIESINGH
Profile icon
Valentina43
Profile icon
DianaLopez2
Profile icon
DaisyJohns
Profile icon
MarlonLeonMoral
Profile icon
5235831
Profile icon
iiujk
Profile icon
herry2003
Profile icon
KaiaBrown
Profile icon
JefferyNelson
Comments
hotnewtop
Profile icon
heyitsmarcus

Hey @linda231,

I can see why you were originally getting an error. The amount of beginning parenthesis you have in the final print line of your code doesn't match the amount of ending parenthesis. You needed two more at the end for the code to compile.

However

Your logic for the program is incorrect. I'm laying this out in a format that should be easier to understand. I would personally change x,y,j,k to variables that make more sense to what they are such as feet1, inches1, feet2, inches2. And that is what I did in my example for easier understanding.

Please review the comments in the code below to understand why I added what I did:

import math feet1=float(input("Enter the Feet for the first piece of fabric: ")) inches1=float(input("Enter the Inches for the first piece of fabric: ")) feet2=float(input("Enter the Feet for the second piece of fabric: ")) inches2=float(input("Enter the Inches for the second piece of fabric: ")) #Get the initial total amount of feet initialFeet = feet1 + feet2 #Get the initial total amount of inches initialInches = inches1 + inches2 #Get the remaining inches which is a modulus of 12 (12 inches in 1 foot) remainingInches = initialInches % 12 #Get the addiitonal feet to add from the total initial inches #This total has to be divided by 12 and then have a floor done on it which will remove any decimal values additionalFeet = math.floor(initialInches / 12) #The total feet will be the initial feet (feet1 and feet2) plus the additional calculated feet totalFeet = initialFeet + additionalFeet print ("Total: Feet: " + str(totalFeet) + " Inches: " + str(remainingInches))

And here is a copy of the program above: https://repl.it/@heyitsmarcus/Feet-and-Inches

If this solves your problem, please upvote and select my answer as the accepted answer to close this question.

Profile icon
linda231

@heyitsmarcus Thanks, I figured it out! I wasn't expecting this much of an response but I'm glad I did!

Profile icon
heyitsmarcus

@linda231, you are very welcome! I try to be "extra" in all my responses so that you, and others, can learn from answered posts. Cheers!

Profile icon
ash15khng

If you tell us

  1. what error are you getting
  2. send a link to a repl to make it easier to help
  3. describe your problem (something more specific than "And it just ain't working")
    we could probably help better
Profile icon
mwilki7

What part of the program isn't working?

Profile icon
linda231

@mwilki7 It wasn't matching what Edhesive wanted. No need to worry I figured it all out!

Profile icon
JustARatherRidi

Problem 1: You're missing two closing parentheses after your print statement

Problem 2: What you're printing isn't quite right. After inputting the values, you should do something like this:

feet = x + j inches = y + k # If we have 12 or more inches, add the # appropriate number of feet feet += inches // 12 # Divide inches by 12, get the remainder, # and make that the value of 'inches' inches = inches % 12 print('Feet:', feet, 'Inches:', inches)

Although I did answer this question because it wasn't too confusing, next time onwards you should definitely (at least) do the things @ash15khng has mentioned.

Profile icon
heyitsmarcus

@JustARatherRidi they were missing 2 parenthesis. But also, your solution is not right as it is incorrect in the logic and missing requirements.

Profile icon
JustARatherRidi

@heyitsmarcus Fixed it now, but I definitely messed that up 😛
You win this one

Profile icon
heyitsmarcus

@JustARatherRidi No winning here man. We're all trying to help people, but we must be wary about giving them the correct information, that's all.

Profile icon
JustARatherRidi

@heyitsmarcus True, but you won in the sense that you've managed to help the op better.

Profile icon
heyitsmarcus

@JustARatherRidi As you learn more, so shall you too help better :)

Profile icon
linda231

@JustARatherRidi Thanks! I'll remember your advice!