質問編集履歴
3
回答を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -98,23 +98,31 @@
|
|
98
98
|
|
99
99
|
def is_divisible(a, b):
|
100
100
|
|
101
|
-
|
101
|
+
return a % b == 0
|
102
102
|
|
103
103
|
|
104
104
|
|
105
|
-
def is_power():
|
105
|
+
def is_power(a, b):
|
106
106
|
|
107
|
-
if
|
107
|
+
if a <=0 or b <= 0:
|
108
108
|
|
109
|
-
return a
|
109
|
+
return False
|
110
110
|
|
111
|
+
elif a == 1 and b == 1:
|
111
112
|
|
113
|
+
return True
|
112
114
|
|
113
|
-
|
115
|
+
else:
|
114
116
|
|
117
|
+
if is_divisible(a, b):
|
115
118
|
|
119
|
+
a = a/b
|
116
120
|
|
117
|
-
|
121
|
+
is_power(a, b-1)
|
122
|
+
|
123
|
+
else:
|
124
|
+
|
125
|
+
return False
|
118
126
|
|
119
127
|
```
|
120
128
|
|
2
自分なりの回答を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,9 +94,29 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
+
```
|
98
|
+
|
97
|
-
|
99
|
+
def is_divisible(a, b):
|
100
|
+
|
101
|
+
return a % b == 0
|
98
102
|
|
99
103
|
|
104
|
+
|
105
|
+
def is_power():
|
106
|
+
|
107
|
+
if is_divisible(a, b):
|
108
|
+
|
109
|
+
return a == b ** n and a / b == b ** m
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
新たな文字n,mを使うことは間違いだと言うことはわかっていますが、自分なりに考えた結果です。
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
再帰については初心者向けの教科書に書いてあることは理解したつもりだったのですが、この問題にどう活用すればいいのかわかりませんでした。
|
118
|
+
|
119
|
+
```
|
100
120
|
|
101
121
|
### 補足情報(FW/ツールのバージョンなど)
|
102
122
|
|
1
問題原文を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,13 +50,29 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
###
|
53
|
+
### 原文
|
54
54
|
|
55
55
|
|
56
56
|
|
57
57
|
```
|
58
58
|
|
59
|
-
|
59
|
+
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.
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
Does the submission include the is_divisible function from Section 6.4 of the textbook?
|
66
|
+
|
67
|
+
Does the submission implement an is_power function that takes two arguments?
|
68
|
+
|
69
|
+
Does the is_power function call is_divisible?
|
70
|
+
|
71
|
+
Does the is_power function call itself recursively?
|
72
|
+
|
73
|
+
Does the is_power function include code for the base case of the two arguments being equal?
|
74
|
+
|
75
|
+
Does the is_power function include code for the base case of the second argument being "1"?
|
60
76
|
|
61
77
|
```
|
62
78
|
|