質問編集履歴
3
回答を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,15 +48,19 @@
|
|
48
48
|
|
49
49
|
```
|
50
50
|
def is_divisible(a, b):
|
51
|
-
|
51
|
+
return a % b == 0
|
52
52
|
|
53
|
-
def is_power():
|
53
|
+
def is_power(a, b):
|
54
|
+
if a <=0 or b <= 0:
|
55
|
+
return False
|
56
|
+
elif a == 1 and b == 1:
|
57
|
+
return True
|
58
|
+
else:
|
54
|
-
|
59
|
+
if is_divisible(a, b):
|
55
|
-
|
60
|
+
a = a/b
|
56
|
-
|
57
|
-
|
61
|
+
is_power(a, b-1)
|
58
|
-
|
62
|
+
else:
|
59
|
-
|
63
|
+
return False
|
60
64
|
```
|
61
65
|
### 補足情報(FW/ツールのバージョンなど)
|
62
66
|
問題文は英語で出題されており、Google翻訳したものをそのまま載せているので、一部日本語がおかしなところがあるかもしれません。
|
2
自分なりの回答を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -46,8 +46,18 @@
|
|
46
46
|
|
47
47
|
### 試したこと
|
48
48
|
|
49
|
+
```
|
49
|
-
|
50
|
+
def is_divisible(a, b):
|
51
|
+
return a % b == 0
|
50
52
|
|
53
|
+
def is_power():
|
54
|
+
if is_divisible(a, b):
|
55
|
+
return a == b ** n and a / b == b ** m
|
56
|
+
|
57
|
+
新たな文字n,mを使うことは間違いだと言うことはわかっていますが、自分なりに考えた結果です。
|
58
|
+
|
59
|
+
再帰については初心者向けの教科書に書いてあることは理解したつもりだったのですが、この問題にどう活用すればいいのかわかりませんでした。
|
60
|
+
```
|
51
61
|
### 補足情報(FW/ツールのバージョンなど)
|
52
62
|
問題文は英語で出題されており、Google翻訳したものをそのまま載せているので、一部日本語がおかしなところがあるかもしれません。
|
53
63
|
私は大学でPythonについて学び始めたばかりで、いままでにいかなる言語でもコードを書いたことのない完全初心者です。素人にもわかるような言葉で説明していただけたらうれしいです。
|
1
問題原文を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,10 +24,18 @@
|
|
24
24
|
しかしis_power関数がどうしても書けませんので、お忙しいとは思いますが、どなたか解説していただけると幸いです。
|
25
25
|
よろしくお願いいたします。
|
26
26
|
|
27
|
-
###
|
27
|
+
### 原文
|
28
28
|
|
29
29
|
```
|
30
|
-
|
30
|
+
A number, a, is a power of b if it is divisible by b and a/b is a power of b. Write a function called is_power that takes parameters a and b and returns True if a is a power of b. Note: you will have to think about the base case.
|
31
|
+
|
32
|
+
|
33
|
+
Does the submission include the is_divisible function from Section 6.4 of the textbook?
|
34
|
+
Does the submission implement an is_power function that takes two arguments?
|
35
|
+
Does the is_power function call is_divisible?
|
36
|
+
Does the is_power function call itself recursively?
|
37
|
+
Does the is_power function include code for the base case of the two arguments being equal?
|
38
|
+
Does the is_power function include code for the base case of the second argument being "1"?
|
31
39
|
```
|
32
40
|
|
33
41
|
### 該当のソースコード
|