teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

can110様の回答を自分なりに解釈して作ってみました。

2021/05/01 05:38

投稿

dokugakusets
dokugakusets

スコア10

title CHANGED
File without changes
body CHANGED
@@ -3,6 +3,7 @@
3
3
  コード
4
4
  def kazoeru(bunsho, shiin):
5
5
  countC=0
6
+ countV=0
6
7
  alphabet_list=("abcdefghijklmnopqrstuvwxyz")
7
8
  for i in bunsho:
8
9
  if i in alphabet_list:
@@ -10,24 +11,19 @@
10
11
  if i not in my_list:
11
12
  shiin=True
12
13
  countC+=1
13
- return(countC)
14
- bunsho=("lundberg backdrop us phd formate polemic")
15
- print(kazoeru(bunsho, True))
16
14
 
17
- def kazoeru(bunsho, shiin):
18
- countV=0
15
+ else:
19
- alphabet_list=("abcdefghijklmnopqrstuvwxyz")
20
- for j in bunsho:
21
- if j in alphabet_list:
22
- my_list =["a", "e", "i", "o", "u"]
23
- if j in my_list:
24
16
  shiin=False
25
17
  countV+=1
18
+ if shiin==True:
19
+ return(countC)
20
+ else:
26
- return(countV)
21
+ return(countV)
27
22
 
28
23
 
29
24
  bunsho=("but thy eternal summer shall not fade")
25
+ print(kazoeru(bunsho, True))
26
+ print(kazoeru(bunsho, False))
30
27
 
31
- print(kazoeru(bunsho, False))
32
28
  ```
33
29
  よろしくお願いします。

4

ご指摘いただきまして、ありがとうございます。コピペしました。

2021/05/01 05:38

投稿

dokugakusets
dokugakusets

スコア10

title CHANGED
File without changes
body CHANGED
@@ -1,31 +1,33 @@
1
1
  文章内の母音と子音を分けて各総数を出す式を作ってみたのですが、文章によっては正しく答えが出せないのですが、バグが見つけられません。
2
2
  ```python3
3
3
  コード
4
-
5
4
  def kazoeru(bunsho, shiin):
6
5
  countC=0
7
6
  alphabet_list=("abcdefghijklmnopqrstuvwxyz")
8
7
  for i in bunsho:
9
8
  if i in alphabet_list:
10
- my_list =["a","e","i","o","u"]
9
+ my_list =["a", "e", "i", "o", "u"]
11
10
  if i not in my_list:
12
11
  shiin=True
13
- countC +=1
12
+ countC+=1
14
13
  return(countC)
15
- bunsho=("shall i compare thee to a summer's day?")
14
+ bunsho=("lundberg backdrop us phd formate polemic")
16
- print(kazoeru(bunsho, True)
15
+ print(kazoeru(bunsho, True))
17
16
 
18
17
  def kazoeru(bunsho, shiin):
19
18
  countV=0
20
19
  alphabet_list=("abcdefghijklmnopqrstuvwxyz")
21
20
  for j in bunsho:
22
21
  if j in alphabet_list:
23
- my_list =["a","e","i","o","u"]
22
+ my_list =["a", "e", "i", "o", "u"]
24
- if j in my_list:
23
+ if j in my_list:
25
- shiin=False
24
+ shiin=False
26
- countV +=1
25
+ countV+=1
27
26
  return(countV)
27
+
28
+
28
- bunsho=("shall i compare thee to a summer's day?")
29
+ bunsho=("but thy eternal summer shall not fade")
30
+
29
- print(kazoeru(bunsho, False)
31
+ print(kazoeru(bunsho, False))
30
32
  ```
31
33
  よろしくお願いします。

3

```を最後の行の下に入れてみました。これで合ってますでしょうか?

2021/04/29 05:54

投稿

dokugakusets
dokugakusets

スコア10

title CHANGED
File without changes
body CHANGED
@@ -27,6 +27,5 @@
27
27
  return(countV)
28
28
  bunsho=("shall i compare thee to a summer's day?")
29
29
  print(kazoeru(bunsho, False)
30
-
30
+ ```
31
-
32
31
  よろしくお願いします。

2

直してみました。子音と母音の各々の総数を一つの関数で出したかったのですが、うまくいかなかったので、二つに分けてしまいました。本当は一つにまとめるのが理想です。Falseの時は正解になるのですが、Tru

2021/04/28 10:39

投稿

dokugakusets
dokugakusets

スコア10

title CHANGED
File without changes
body CHANGED
@@ -1,31 +1,32 @@
1
1
  文章内の母音と子音を分けて各総数を出す式を作ってみたのですが、文章によっては正しく答えが出せないのですが、バグが見つけられません。
2
2
  ```python3
3
3
  コード
4
- ```def kazoeru(bunsho, shiin):
5
- countC=0
6
- alphabet_list=("abcdefghijklmnopqrstuvwxyz")
7
- for i in bunsho:
8
- if i in alphabet_list:
9
- my_list =["a","e","i","o","u"]
10
- if i not in my_list:
11
- shiin=True
12
- countC +=1
13
- return(countC)
14
- bunsho=("shall i compare thee to a summer's day?")
15
- print(kazoeru(bunsho, True)
16
4
 
17
- def kazoeru(bunsho, shiin):
5
+ def kazoeru(bunsho, shiin):
18
- countV=0
6
+ countC=0
19
- alphabet_list=("abcdefghijklmnopqrstuvwxyz")
7
+ alphabet_list=("abcdefghijklmnopqrstuvwxyz")
20
- for j in bunsho:
8
+ for i in bunsho:
21
- if j in alphabet_list:
9
+ if i in alphabet_list:
22
-  my_list =["a","e","i","o","u"]
10
+ my_list =["a","e","i","o","u"]
23
-  if j in my_list:
11
+ if i not in my_list:
24
-  shiin=False
12
+ shiin=True
25
-  countV +=1
13
+ countC +=1
26
- return(countV)
14
+ return(countC)
27
- bunsho=("shall i compare thee to a summer's day?")
15
+ bunsho=("shall i compare thee to a summer's day?")
28
- print(kazoeru(bunsho, False)
16
+ print(kazoeru(bunsho, True)
29
- ```
30
17
 
18
+ def kazoeru(bunsho, shiin):
19
+ countV=0
20
+ alphabet_list=("abcdefghijklmnopqrstuvwxyz")
21
+ for j in bunsho:
22
+ if j in alphabet_list:
23
+ my_list =["a","e","i","o","u"]
24
+ if j in my_list:
25
+ shiin=False
26
+ countV +=1
27
+ return(countV)
28
+ bunsho=("shall i compare thee to a summer's day?")
29
+ print(kazoeru(bunsho, False)
30
+
31
+
31
32
  よろしくお願いします。

1

操作が間違っていたようで、申し訳ありません!これで見えますでしょうか?

2021/04/28 06:21

投稿

dokugakusets
dokugakusets

スコア10

title CHANGED
File without changes
body CHANGED
@@ -1,30 +1,31 @@
1
1
  文章内の母音と子音を分けて各総数を出す式を作ってみたのですが、文章によっては正しく答えが出せないのですが、バグが見つけられません。
2
2
  ```python3
3
3
  コード
4
- def kazoeru(bunsho, shiin):
4
+ ```def kazoeru(bunsho, shiin):
5
- countC=0
5
+ countC=0
6
- alphabet_list=("abcdefghijklmnopqrstuvwxyz")
6
+ alphabet_list=("abcdefghijklmnopqrstuvwxyz")
7
- for i in bunsho:
7
+ for i in bunsho:
8
- if i in alphabet_list:
8
+ if i in alphabet_list:
9
- my_list =["a","e","i","o","u"]
9
+ my_list =["a","e","i","o","u"]
10
- if i not in my_list:
10
+ if i not in my_list:
11
- shiin=True
11
+ shiin=True
12
- countC +=1
12
+ countC +=1
13
- return(countC)
13
+ return(countC)
14
- bunsho=("shall i compare thee to a summer's day?")
14
+ bunsho=("shall i compare thee to a summer's day?")
15
- print(kazoeru(bunsho, True)
15
+ print(kazoeru(bunsho, True)
16
16
 
17
- def kazoeru(bunsho, shiin):
17
+ def kazoeru(bunsho, shiin):
18
- countV=0
18
+ countV=0
19
- alphabet_list=("abcdefghijklmnopqrstuvwxyz")
19
+ alphabet_list=("abcdefghijklmnopqrstuvwxyz")
20
- for j in bunsho:
20
+ for j in bunsho:
21
- if j in alphabet_list:
21
+ if j in alphabet_list:
22
-  my_list =["a","e","i","o","u"]
22
+  my_list =["a","e","i","o","u"]
23
-  if j in my_list:
23
+  if j in my_list:
24
-  shiin=False
24
+  shiin=False
25
-  countV +=1
25
+  countV +=1
26
- return(countV)
26
+ return(countV)
27
- bunsho=("shall i compare thee to a summer's day?")
27
+ bunsho=("shall i compare thee to a summer's day?")
28
- print(kazoeru(bunsho, False)```
28
+ print(kazoeru(bunsho, False)
29
+ ```
29
30
 
30
31
  よろしくお願いします。