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

質問編集履歴

2

書式の改善

2018/02/28 02:07

投稿

NateRive
NateRive

スコア10

title CHANGED
File without changes
body CHANGED
@@ -15,7 +15,7 @@
15
15
  #chosse the difficulty of game level_answer
16
16
  #output:the list of questions and answers of selected level
17
17
 
18
- game_level = level_selection()
18
+ game_level = level_selection()  #ここのgame_levelがNoneになっています。
19
19
  print ("game_level " + str(game_level))
20
20
  ```
21
21
 

1

コードをテキストに変えました。

2018/02/28 02:07

投稿

NateRive
NateRive

スコア10

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,24 @@
1
+ ```ここに言語を入力
2
+ def level_selection():
3
+ user_input = raw_input("Choose the difficulty of quize in number or string: (1.Easy 2.Medium 3.Hard)").lower()
4
+ game_level = ["easy","medium","hard"]
5
+ max = 4
6
+ if user_input in game_level:
7
+ print ("Debug user_input = " + user_input) #debug
8
+ return user_input
9
+ elif user_input in str(range(max)):
10
+ return game_level[int(user_input) - 1]
11
+ else:
1
- ![イメージ説明](2c6961630d9a7537e590becb2964c95b.png)
12
+ print("Incorrect level! Try again!")
13
+ print ("Debug user_input = " + user_input) #debug
14
+ level_selection()
15
+ #chosse the difficulty of game level_answer
16
+ #output:the list of questions and answers of selected level
2
17
 
18
+ game_level = level_selection()
19
+ print ("game_level " + str(game_level))
20
+ ```
21
+
3
22
  上記のプログラムを動かし、一発で正しい値をuser_inputで入力すると下の通り問題なく作動します。
4
23
 
5
24
 
@@ -13,7 +32,26 @@
13
32
  現にstrでstring型に直さなければ、エラーが出ます。
14
33
 
15
34
 
35
+ ```ここに言語を入力
36
+ def level_selection():
37
+ user_input = raw_input("Choose the difficulty of quize in number or string: (1.Easy 2.Medium 3.Hard)").lower()
38
+ game_level = ["easy","medium","hard"]
39
+ max = 4
40
+ if user_input in game_level:
41
+ print ("Debug user_input = " + user_input) #debug
42
+ return user_input
43
+ elif user_input in str(range(max)):
44
+ return game_level[int(user_input) - 1]
45
+ else:
16
- ![イメージ説明](17aa6e6bec8d999706c168664bcf4706.png)
46
+ print("Incorrect level! Try again!")
47
+ print ("Debug user_input = " + user_input) #debug
48
+ level_selection()
49
+ #chosse the difficulty of game level_answer
50
+ #output:the list of questions and answers of selected level
51
+
52
+ game_level = level_selection()
53
+ print ("game_level " + game_level) #str()を取りました。
54
+ ```
17
55
             **↓**
18
56
 
19
57