218k views
2 votes
We want to build a fence, but need to weigh the balance between the number of poles and the number of fence segments that we have to buy. Write a function called FenceCalculator, that takes two scalar Inputs: L, the length of a fence needed and S, the length of one segment of fencing. Outputs: the number of fence segments needed and the number of poles to go with it. Note: that a segment can be cut shorter, but not longer. For example, to build a 75 m long straight fence using 10 m segments, we need 8 segments. prob09 [needed segments, needed poles]

1 Answer

3 votes

Answer:

def FenceCalculator(L, S):

m = L % S

if m == 0:

segment = int(L/S)

elif m < S:

segment = int(L/S) + 1

print(segment)

Step-by-step explanation:

* The code is in Python

- Create a function FenceCalculator() that takes the length of a fence - L, and the length of one segment of a fence - S, as a parameter

- Get the module of the L respect to S

- If the module is equal to 0, then the segment amount is equal to the integer value of L/S

- If the module is smaller than S, then the segment amount is equal to the integer value of L/S + 1

- Print the segment

User Rhesa
by
3.3k points