# 困っていること
日付を入力して、入力した日が1900年1月1日から数え始めて何日目になるかをカウントするプログラムを作っているのですが、TypeError: an integer is required (got type str) というエラーの原因が分からず困っています。検索しても分かりません。
該当のソースコード
python
1import datetime 2b=input("日付を入力してください:") 3a=datetime.date(1900,1,1) 4c=datetime.date(b) 5print("今日は2019年1月1日から数えて"+str((c-a).days)+"日目です")
入力した数値とエラーメッセージ
python
1日付を入力してください:2019,05,22 2Traceback (most recent call last): 3 File "(ファイル名)", line 4, in <module> 4 c=datetime.date(b) 5TypeError: an integer is required (got type str)
試したこと
エラーメッセージにc=datetime.date(b)と(got tipe str)とあるので、c=datetime.date(str(b))にしてみましたが、また同じエラーが出ました。
python
1import datetime 2b=input("日付を入力してください:") 3a=datetime.date(1900,1,1) 4c=datetime.date(str(b)) 5print("今日は2019年1月1日から数えて"+str((c-a).days)+"日目です")
python
1日付を入力してください:2019,05,22 2Traceback (most recent call last): 3 File (ディレクトリ名), line 4, in <module> 4 c=datetime.date(str(b)) 5TypeError: an integer is required (got type str)
回答1件
あなたの回答
tips
プレビュー