требуется целое число (получил тип str) - PullRequest
0 голосов
/ 27 февраля 2020

эта программа считает количество дней между двумя датами

это ошибка:

line 14, in <module>
    f_date = date(d1, m1, y1)
ValueError: day is out of range for month
#program that counts the amount of days between two dates
from datetime import date

print("Hi,this program counts the amount of days between two dates, press enter and follow the instructions without writing spaces")

d1=int(input("tell me the day of the starting date"))
m1=int(input("now the month"))
y1=int(input("and the year"))

d2=int(input("now i would need the day of the the second date"))
m2=int(input("then the month"))
y2=int(input("and finally the year"))

f_date = date(d1, m1, y1)
l_date = date(d2, m2, y2)
delta = l_date - f_date
print(delta.days)


1 Ответ

1 голос
/ 27 февраля 2020

Это потому, что функция datetime.date () - это дата (y, m, d) вместо даты (d, m, y) https://docs.python.org/3/library/datetime.html#date -объекты

Это изменение в коде должно исправить это (при условии, что ваши пользовательские данные верны):

f_date = date(y1, m1, d1)
l_date = date(y2, m2, d2)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...