Programming Questions

ThreeFive Multiples Incorrect Test Case

I'm getting incorrect outputs for test case for input == 31 and 17. I checked the math and the outputs are 270 and 75 respectively, which I think are correct. Please advise.

```
def ThreeFiveMultiples(num):
multiples = []
for i in range (0, num, 5):
multiples.append(i)
for j in range (0, num, 3):
multiples.append(j)
# code goes here
total = sum(multiples)
return total
# keep this function call here
# to see how to enter arguments in Python scroll down
print ThreeFiveMultiples(raw_input())
```

tomsun
posted this question on 4/7/15 **|**

10

It looks like if the number a multiple of 5 and 3 you are counting them twice.

mattlarsh

answered on 04/08/15

1

Just a minor issue but the code fails because raw_input() expects a string but your code is treating num as an int.
try the following change.

```
def ThreeFiveMultiples(num):
num = int(num)
multiples = []
for i in range (0, num, 5):
multiples.append(i)
for j in range (0, num, 3):
multiples.append(j)
# code goes here
total = sum(multiples)
return total
# keep this function call here
# to see how to enter arguments in Python scroll down
print ThreeFiveMultiples(raw_input())
```

when I tested the outputs I got were 270 and 75 with your inputs.
gbrish

answered on 04/08/15

0

To display code include the following tags:

```
def ThreeFiveMultiples(num):
multiples = []
for i in range (0, num, 5):
multiples.append(i)
for j in range (0, num, 3):
multiples.append(j)
# code goes here
total = sum(multiples)
return total
print ThreeFiveMultiples(int(raw_input()))
```

raw_input returns string, it has to be converted to int
mustyMustapha

answered on 06/24/15

Log in to write an answer.