回答編集履歴
2
追記
answer
CHANGED
@@ -16,4 +16,25 @@
|
|
16
16
|
# print(a)
|
17
17
|
total = total + a # これも total += a で充分では
|
18
18
|
a += diff
|
19
|
+
```
|
20
|
+
|
21
|
+
あるいは
|
22
|
+
---
|
23
|
+
while文ではなくfor文を使った方が書きやすそうです。
|
24
|
+
等差数列ならばrangeで充分表現できるからです。
|
25
|
+
```Python
|
26
|
+
def multiple_total(a, b):
|
27
|
+
total = 0
|
28
|
+
|
29
|
+
# start, stop, step
|
30
|
+
for i in range(a, b+1, a):
|
31
|
+
total += i
|
32
|
+
|
33
|
+
return total
|
34
|
+
```
|
35
|
+
|
36
|
+
次のようにも書けますし。
|
37
|
+
```Python
|
38
|
+
def multiple_total(a, b):
|
39
|
+
return sum(range(a, b+1, a))
|
19
40
|
```
|
1
追記
answer
CHANGED
@@ -7,4 +7,13 @@
|
|
7
7
|
print(a)
|
8
8
|
total = total + a
|
9
9
|
a += a
|
10
|
+
```
|
11
|
+
|
12
|
+
元々のaの値をどこかに保持しておく必要がありますね。
|
13
|
+
```Python
|
14
|
+
diff = a
|
15
|
+
while a <= b:
|
16
|
+
# print(a)
|
17
|
+
total = total + a # これも total += a で充分では
|
18
|
+
a += diff
|
10
19
|
```
|