So, here's my solution to implementing nextDay and you'll note that I start with
a docstring. This is treated as a special common by most Python systems and I
put in this warning to make people realize this [unknown] is not actually
correct. So, it shouldn't be used to schedule, say, the apocalypse, but it's
good for our testing for now. And the logic is quite simple, if the day is less
than 30, since we're assuming all months have 30 days, we increase the day by 1,
and I'm returning a three tuple of the year, the month, and the day. Otherwise,
we need to increase the month, so we're going to advance to the next month and
reset the day to 1. If we're in December, then we need to increase the year by 1
and reset the date to January 1st. As with the larger problem, you should start
this by thinking about some test cases. And see that those behave as expected.
We provided some in the example. One nice thing you'll notice here using the
Python shell provided by [unknown] is that, when I try to use nextDay, I see the
docstring right here. And normally, we want docstrings that are descriptive
here. The warning is very useful. And I give a sample month, day, and year, and
I see that I get the right result. I should note that for some cases, say,
January 30th, the day following January 30th should be January 31st. I'm going
to get February 2nd because of this assumption about all months having 30 days,
and we should try a more difficult case, such as the end of the year. And here,
I'll use December 31st, it would advance the year whether it's December 31st or
December 30th because of that assumption, and we get January 1st, 2013.
Así que, aquí está mi solución a implementar nextDay y te cuenta que empiezo con
una cadena de documentación. Esta es tratado como un común especial por la mayoría de los sistemas de Python y yo
puesto en esta advertencia para que la gente se da cuenta de esto no es en realidad
correcto. Por lo tanto, no debe utilizarse para programar, por ejemplo, el apocalipsis, pero es
bueno para nuestras pruebas por ahora. Y la lógica es bastante simple, si el día es menos
de 30, ya que estamos suponiendo que todos los meses tienen 30 días, podemos aumentar el día 1,
y estoy de regresar de tres tupla del año, el mes y el día. De otra manera,
tenemos que aumentar el mes, por lo que vamos a avanzar al siguiente mes y
restablecer el día a 1. Si estamos en diciembre, entonces tenemos que aumentar el año 1
y restablecer la fecha al 1 de enero. Al igual que con el problema más grande, usted debe protagonizar
esta pensando en algunos casos de prueba. Y ver que quienes se comportan como se espera.
Hemos proporcionado algunos en el ejemplo. Una cosa buena que usted notará aquí usando la
Python proporcionada por [unknown] es que, cuando trato de usar nextDay, veo el
docstring aquí. Y normalmente, queremos docstrings que son descriptivos
Aquí. La advertencia es muy útil. Y le doy un mes muestra, día y año y
Veo que me sale el resultado correcto. Debo señalar que en algunos casos, por ejemplo,
30 de enero, el siguiente día 30 de enero debe ser 31 de enero. estoy yendo
para obtener 02 de febrero a causa de este supuesto sobre todos los meses tienen 30 días,
y debemos tratar de un caso más difícil, como el final del año. Y aquí,
Voy a usar 31 de diciembre, sería avanzar en el año si se trata de 31 de diciembre, o
30 de diciembre a causa de esa suposición, y obtenemos 01 de enero 2013.
これがnextDayを実装する私の解決策です
docstringから始めています
こうすると ほとんどのPythonシステムで
コメントとして扱われます
この仮定が正確ではないことを
知らせるため警告を入れました
スケジュールの使用には向いていないので
仮に黙示録としておきましょう
ですが今のテストには適しています
論理はとても簡単です
もし日数が30日より少なかった場合
すべての月が30日であると仮定しているので
その日に1を加えます
year、month、dayの3つをタプルとして返します
そうでない場合 次の月にする必要があります
月を進めて日付を1日に戻します
12月の場合 次の年にして日付を1月1日に戻します
大きな問題と同様に複数のテストケースを
考えることから始める必要があります
予測どおりに作用するのかを確認します
例を挙げます
与えられたPythonシェルを使うと次の利点があります
nextDayを使用すると
ここでdocstringが確認できるのです
通常 記述的なdocstringがここに必要です
警告はとても有益です
そしてmonth、day、yearのサンプルを与えます
すると正しい結果が取得できます
ただし結果に注意が必要な場合もあります
例えば1月30日は次の日が1月31日のはずです
各月を30日と仮定しているので2月2日になるのです
ではもっと難しい問題に挑戦してみましょう
例えば12月31日です
この仮定では年が変わると12月31日
または12月30日なります
2013年1月1日になりました