def first(): print("今月の収入を入力してください。") income_input = str(input()) print("今月の収入は"+ income_input +"円です。") def second(): print("今月の支出を入力してください。") def put_second(): post = {} print("支払いの内訳を入力してください。(例;お菓子、、、など)") post["pay"] = input() print("金額を入力してください。(例;108)") post["money"] = input() print(post["pay"]+" : "+"¥"+post["money"]) posts.append(post) return posts def other_second(): print("入力された値は無効な値です。") while True: print("[0] : 入力する。") print("[1] : 入力を終える。") sub_input = int(input()) if sub_input == 0: put_second() elif sub_input == 1: break else: other_second() def third(): print("[ 今月の支出内訳一覧を表示します ]") for i,post in enumerate(posts): print("["+str(i)+"] :"+post['pay']+" : "+post['money']) def fourth(): remain = income_input - sum(posts) if remain <= 0: print("残金がありません。") def end(): exit() def exeption(): print("入力された値は無効な値です。") posts = [] while True: print("[0]今月の収入を入力する") print("[1]今月の支出を入力する") print("[2]今月の支出内訳を見る") print("[3]残金を確認する") print("[4]アプリを終了する") main_input = int(input()) if main_input == 0: first() elif main_input == 1: second() elif main_input == 2: third() elif main_input == 3: fourth() elif main_input == 4: end() else: exeption()
と入力し、実行した所
[0]今月の収入を入力する [1]今月の支出を入力する [2]今月の支出内訳を見る [3]残金を確認する [4]アプリを終了する 0 今月の収入を入力してください。 10000 今月の収入は10000円です。 [0]今月の収入を入力する [1]今月の支出を入力する [2]今月の支出内訳を見る [3]残金を確認する [4]アプリを終了する 1 今月の支出を入力してください。 [0] : 入力する。 [1] : 入力を終える。 0 支払いの内訳を入力してください。(例;お菓子、、、など) okasi 金額を入力してください。(例;108) 1000 okasi : ¥1000 [0] : 入力する。 [1] : 入力を終える。 1 [0]今月の収入を入力する [1]今月の支出を入力する [2]今月の支出内訳を見る [3]残金を確認する [4]アプリを終了する 3 Traceback (most recent call last): File "classcheck.py", line 69, in <module> fourth() File "classcheck.py", line 40, in fourth remain = income_input - sum(posts) NameError: name 'income_input' is not defined
と出てしまいました。
この場合income_inputはどこに置けばいいのでしょうか??
また、このsum(posts)は間違っているのでしょうか??
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/12 13:14