212k views
5 votes
Given 2 integer numbers n and m, write a method to collect the multiple of 3 between & excluding n and m.

Ex: input -3 and 3 , output will be 0
Ex: input 3 and -3 , output will be 0
Ex: input -7 and 11 , output will be -6 -3 -30369 submit by the end of the lab
- Via email
- Include: analysis of data and 1 ppt slide of 3 sub-windows:cmd, folder, & code

1 Answer

4 votes

Final answer:

To collect the multiples of 3 between and excluding two integer numbers, n and m, you can use a loop to check each number between n and m. If a number is divisible by 3, it is a multiple of 3.

Step-by-step explanation:

To collect the multiples of 3 between and excluding two integer numbers, n and m, you can use a loop to check each number between n and m. If a number is divisible by 3, it is a multiple of 3. You can add the multiple of 3 to a list or print it directly.

Here is an example code:

def collect_multiples_of_three(n, m):
multiples_of_three = []
for i in range(min(n, m) + 1, max(n, m)):
if i % 3 == 0:
multiples_of_three.append(i)
return multiples_of_three

n = int(input("Enter n: "))
m = int(input("Enter m: "))

result = collect_multiples_of_three(n, m)

for multiple in result:
print(multiple)

User Andrewsi
by
9.5k points