質問編集履歴

3

タイトル

2019/07/25 06:46

投稿

hinako__
hinako__

スコア6

test CHANGED
@@ -1 +1 @@
1
- expected an indented blockの解決
1
+ expected an indented blockの解決方法
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ### 発生している問題・エラーメッセージ
14
14
 
15
- IndentationError : expected an indented blockが出てしまいました。
15
+ IndentationError : IndentationError : expected an indented blockが出てしまいました。
16
16
 
17
17
  エラーメッセージ
18
18
 

2

.

2019/07/25 06:46

投稿

hinako__
hinako__

スコア6

test CHANGED
@@ -1 +1 @@
1
- プログラミング初心者です、、、
1
+ expected an indented blockの解決
test CHANGED
File without changes

1

.

2019/07/25 06:45

投稿

hinako__
hinako__

スコア6

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,151 @@
24
24
 
25
25
 
26
26
 
27
+ python>> 「電話帳DB」アルゴリズムのスケッチ
28
+
29
+
30
+
31
+ from sys import exit
32
+
33
+ import pickle # pickleモジュールを使う
34
+
35
+ import re # 正規表現モジュールを使う
36
+
37
+
38
+
39
+ phone = dict() # グローバル変数
40
+
41
+
42
+
43
+ def main():
44
+
45
+ global phone # グローバル変数を使うための宣言
46
+
47
+
48
+
49
+ # pickleされたものがあるか調べる(step12参照)
50
+
51
+ # あればphoneにloadする
52
+
53
+ # なければ「初回起動」
54
+
55
+
56
+
57
+ # メインメニューを表示し、コマンド番号を受け取る
58
+
59
+ while True:
60
+
61
+ scenestr = input(''' # ユーザから文字列を受け取る
62
+
63
+ 番号を入力してください
64
+
65
+ 1:電話番号を検索
66
+
67
+ 2:電話番号を登録
68
+
69
+ 3:電話番号を削除
70
+
71
+ 4:電話番号を一覧
72
+
27
- python>
73
+ 0:プログラムの終了
74
+
75
+ ->''')
76
+
77
+ if (not re.search(r'^[0-4]$',scenestr)): # 入力値をチェック
78
+
79
+ continue
80
+
81
+ scene = int(scenestr) # 整数に変換
82
+
83
+ # 各コマンドへの分岐(「マニュフォールド」)
84
+
85
+ if scene == 0:
86
+
87
+ 終了()
88
+
89
+ elif scene == 1:
90
+
91
+ 検索()
92
+
93
+ elif scene == 2:
94
+
95
+ 登録()
96
+
97
+ elif scene == 3:
98
+
99
+ 削除()
100
+
101
+ elif scene == 4:
102
+
103
+ 一覧()
104
+
105
+ def 終了():
106
+
107
+ # phoneをpickleする
108
+
109
+ exit()
110
+
111
+ ```> ここに言語を入力
112
+
113
+ コード
114
+
115
+ ```
116
+
117
+ def 検索():
118
+
119
+ # ユーザーから名前を受け取る
120
+
121
+ # 電話番号を表示
122
+
123
+ pass # 関数が未実装ならこれを置いておくこと
124
+
125
+
126
+
127
+ def 登録():
128
+
129
+ global phone # ここは必須
130
+
131
+ # ユーザーから名前を受け取る
132
+
133
+ # ユーザーから電話番号を受け取る
134
+
135
+ if re.search(r'【正規表現パターン】', num): # 「電話番号として適切」かチェック
136
+
137
+ phone[name] = num
138
+
139
+ else:
140
+
141
+ # 「電話番号として不適切です」
142
+
143
+ def 削除():
144
+
145
+ # ユーザーから名前を受け取る
146
+
147
+ if (name in phone):
148
+
149
+ # del phone[name] # これは古い書き方
150
+
151
+ phone.pop(name) # こちらをお勧めする
152
+
153
+ else:
154
+
155
+ # 「その名前の番号は登録されていません」
156
+
157
+ def 一覧():
158
+
159
+ for kv in phone.items(): # キーと値のペアを1つずつ返す
160
+
161
+ k, v = kv
162
+
163
+ # ペアを表示
164
+
165
+
166
+
167
+ if __name__ == '__main__':
168
+
169
+ main()
170
+
171
+
28
172
 
29
173
 
30
174