(SPOILERS) Duct Tape - Python (what do you think of this code?) - Beginner
#import math h = int(input()) # 10 or 6 w = int(input()) # 5 or 3 hin = h*12 # 120 or 72 win = w*12 # 60 or 36 supin = (hin*win)* 2 # 14400 or 5184 dt = (60*12) * 2 # 1440 tapes = (supin / dt) # = 10 or 4 print(-int(-tapes // 1)) #print(math.ceil(tapes)) ------------------------ I wanted to do it without using any imported modules. It took me a while to properly understand the question of this Code Coach... I first thought we were calculation the perimeter, then I thought we were calculating the superficies of each sides of the door frame, but then I decided to read the question again... carefully this time and realized they were asking to cover the whole door with duct tape (what a strange idea). So what I did was convert everything to inches, find the superficies of the door (*2 for each side) and of the duct tape roll and divide them (door superficies / duct tape superficies). I struggled a little bit to find a way to round up numbers to an integer without using math module... I tried to figure it out, but all my ideas were too complicated for such a simple task. I looked at others users suggestion (on stackflows.. etc..) to round up numbers and I couldn't find anything that was simple enough for me and lots of people were arguing... so I decided to ask ChatGPT how I could round up a float without using the math module. At first, ChatGPT gave me an example with the math module, I had to specify more clearly that I didn't want to use the math module. Then, it explained to me that I could use this code : x = 3.7 rounded_up = -int(-x // 1) print(rounded_up) # Output: 4 and said : "This method works by dividing the float x by 1 (to keep it a float), then applying the int() function to truncate the fractional part (effectively rounding towards zero), and finally negating the result before passing it back to int() to simulate ceiling rounding." and asked the AI to break it down for me. That's where the AI started failing and I had to decipher that bit of code. I'll explain more below.