+ 2
Duct tape challenge
Task: Given the height and width of the door, determine how many rolls of duct tape you will need (a roll of duct tape is 60 feet long and 2 inches wide and there are 12 inches in each foot). Don't forget both sides of the door! This code is failing 2 out of 5 test, what's wrong h=int(input())*12 w=int(input())*12 door_area=h*w tape_area=60*12*2 print((door_area // tape_area) * 2)
9 Answers
+ 1
Additional information to wqd's answer:
The import math / math.ceil( ) function rounds up the number of tapes, since the task is to output the amount of (full) duct tape rolls you need
The reason that trying to use the round( ) method results in an error here is probably due to the fact that all numbers with a 0.5 decimal are rounded to the next even integer (i.e. 1.5 gets rounded to 2, but 2.5 gets rounded to 2 as well). This means that if you need 4.5 rolls to tape up both sides of the door, round ( ) is gonna output 4 instead of 5 duct tape rolls.
Note:
Similiar to math.ceil to round up, you can use math.floor to round down
Don't forget to type import math at the beginning
+ 1
Hey!
Why does the task say that tape is 60 feet long, cause it shuld be 60 inches long instead?
Because we devide 60 by 12 in the right code
+ 1
Wait wqd dqwwdqwd did your code pass the test that way?
Alexander Glyantsev im not sure that the math for the square tape is right in his answer.. I think you would have to do 60*12*2 to get the square tape in inches and then divide by 12 to get the square tape in foot
since the tape is 60 foot long but only 2 inches wide which means you would have to norm both to the same unit to get the right amount of area the tape covers
+ 1
But in order to get the right answers in the task you should 60 devide by 12 :/
+ 1
Does it say so? I just converted everything into inches and it worked perfectly fine
Dividing by 12 doesnt make any sense mathematically does it?
+ 1
You are right man, got it, ty
0
import math
height = int(input())
width = int(input())
square_door = height * width * 2
square_tape = 60 / 12 * 2
need_tape = square_door / square_tape
print(math.ceil(need_tape))
0
You are welcome bro!