回答編集履歴

4

else

2022/11/13 06:49

投稿

Cocode
Cocode

スコア2314

test CHANGED
@@ -1,7 +1,7 @@
1
1
  2パターン用意してみました。
2
2
 
3
3
  ```python
4
- # 全部if。条件に一致したらreturnで関数を終了。以降の行は実行されない
4
+ # ほぼ全部if。条件に一致したらreturnで関数を終了。以降の行は実行されない
5
5
  def get_grade():
6
6
  # 入力された文字列としての数字を、int型に変換
7
7
  score = int(input('Your score?'))
@@ -18,7 +18,7 @@
18
18
  if score <= 100:
19
19
  print('Grade3')
20
20
  return
21
- if 100 < score:
21
+ else:
22
22
  print('error1')
23
23
 
24
24
  get_grade()

3

fix

2022/11/13 06:47

投稿

Cocode
Cocode

スコア2314

test CHANGED
@@ -9,13 +9,13 @@
9
9
  if score < 0:
10
10
  print('error')
11
11
  return
12
- if 0 <= score <= 40:
12
+ if score <= 40:
13
13
  print('Grade1')
14
14
  return
15
- if 41 <= score <= 70:
15
+ if score <= 70:
16
16
  print('Grade2')
17
17
  return
18
- if 71 <= score <= 100:
18
+ if score <= 100:
19
19
  print('Grade3')
20
20
  return
21
21
  if 100 < score:

2

all if

2022/11/13 06:45

投稿

Cocode
Cocode

スコア2314

test CHANGED
@@ -1,11 +1,14 @@
1
1
  2パターン用意してみました。
2
2
 
3
3
  ```python
4
- # ほぼ全部if。条件に一致したらreturnで関数を終了。以降の行は実行されない
4
+ # 全部if。条件に一致したらreturnで関数を終了。以降の行は実行されない
5
5
  def get_grade():
6
6
  # 入力された文字列としての数字を、int型に変換
7
7
  score = int(input('Your score?'))
8
8
 
9
+ if score < 0:
10
+ print('error')
11
+ return
9
12
  if 0 <= score <= 40:
10
13
  print('Grade1')
11
14
  return
@@ -15,11 +18,8 @@
15
18
  if 71 <= score <= 100:
16
19
  print('Grade3')
17
20
  return
18
- if score > 100:
21
+ if 100 < score:
19
22
  print('error1')
20
- return
21
- else:
22
- print('error')
23
23
 
24
24
  get_grade()
25
25
  ```

1

ごじ

2022/11/13 06:40

投稿

Cocode
Cocode

スコア2314

test CHANGED
@@ -24,7 +24,7 @@
24
24
  get_grade()
25
25
  ```
26
26
  ```python
27
- # 配列を利用した変わった方法
27
+ # リストを利用した変わった方法
28
28
  def get_grade_2():
29
29
  # 入力された文字列としての数字を、int型に変換
30
30
  score = int(input('Your score?'))