我很难理解函数中函数的概念。
例如,我将2017-02-22 11:36:08.037315: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights not found in checkpoint
2017-02-22 11:36:08.037382: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights/Adam not found in checkpoint
2017-02-22 11:36:08.037494: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases/Adam not found in checkpoint
2017-02-22 11:36:08.037499: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights/Adam_1 not found in checkpoint
2017-02-22 11:36:08.037538: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights not found in checkpoint
2017-02-22 11:36:08.037615: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases not found in checkpoint
2017-02-22 11:36:08.037618: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases/Adam_1 not found in checkpoint
2017-02-22 11:36:08.038098: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights/Adam_1 not found in checkpoint
2017-02-22 11:36:08.038121: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights/Adam not found in checkpoint
2017-02-22 11:36:08.038222: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/biases not found in checkpoint
2017-02-22 11:36:08.038229: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/weights not found in checkpoint
2017-02-22 11:36:08.038233: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/biases/Adam_1 not found in checkpoint
的参数包含在函数time_from_utc
中。就好像我用to_24_hour_clock
的参数替换to_24_hour_clock
的参数,我并不真正理解发生了什么。
提前感谢您的反馈。
def to_24_hour_clock(hours): """ (number) -> numbertime_from_utc
Write your get_hours function definition here:
def get_hours(seconds): """ (int) -> int
hours is a number of hours since midnight. Return the hour as seen on a 24-hour clock. Precondition: hours >= 0 >>> to_24_hour_clock(24) 0 >>> to_24_hour_clock(48) 0 >>> to_24_hour_clock(25) 1 >>> to_24_hour_clock(4) 4 >>> to_24_hour_clock(28.5) 4.5 """ return hours % 24
Write your get_minutes function definition here:
def get_minutes(seconds): """ (int) -> int
Input a time in seconds and it will return the total number of hours that the inputted time contains. Precondition: seconds >= 0 >>> get_hours(3600) 1.0 >>> get_hours(3500) 0.9722222222222222 >>> get_hours(17363) 4.823055555555555 >>> get_hours(177329) 49.25805555555556 >>> """ return seconds / 3600
Write your get_seconds function definition here:
Input a time in seconds and it will return the total number of minutes that the inputted time contains. Precondition: seconds >= 0 >>> get_minutes(3600) 60.0 >>> get_minutes(240) 4.0 >>> get_minutes(90) 1.5 """ return seconds % 60
def time_to_utc(utc_offset, time): """ (number, float) -> float
""" (int) -> int Input a time in seconds and it will return the total number of seconds >>> get_seconds(3930) 30 """ return seconds
def time_from_utc(utc_offset, time): """ (number, float) -> float
Return time at UTC+0, where utc_offset is the number of hours away from UTC+0. >>> time_to_utc(+0, 12.0) 12.0 >>> time_to_utc(+1, 12.0) 11.0 >>> time_to_utc(-1, 12.0) 13.0 >>> time_to_utc(-11, 18.0) 5.0 >>> time_to_utc(-1, 0.0) 1.0 >>> time_to_utc(-1, 23.0) 0.0 """
有些测试失败了:
[TestGetSeconds]您的代码引发了一个意外的异常:module' a1'没有>属性' get_seconds'
[TestGetSeconds]您的代码引发了一个意外的异常:module' a1'没有>属性' get_seconds'
[TestGetSeconds]您的代码引发了一个意外的异常:module' a1'没有>属性' get_seconds'
[TestGetSeconds]您的代码引发了一个意外的异常:module' a1'没有>属性' get_seconds'
[TestTimeToUtc]您的代码引发了意外的异常:不支持的操作数>类型为 - :' NoneType'并且'浮动'
[TestTimeToUtc]您的代码引发了意外的异常:不支持的操作数>类型为 - :' NoneType'并且'浮动'
[TestTimeToUtc]您的代码引发了意外的异常:不支持的操作数>类型为 - :' NoneType'并且'浮动'
[TestTimeToUtc]您的代码引发了意外的异常:不支持的操作数>类型为 - :' NoneType'并且'浮动'
答案 0 :(得分:0)
没有所有评论,所以我们可以看到你的代码
def to_24_hour_clock(hours):
return hours % 24
def get_hours(seconds):
return seconds / 3600
def get_minutes(seconds):
return seconds % 60
### Write your get_seconds function definition here:
return seconds
def time_to_utc(utc_offset, time):
"""
OK, one comment - this returns nothing, so calling it give you None
"""
def time_from_utc(utc_offset, time):
return to_24_hour_clock(utc_offset + time)
有两个明显的问题。
首先,我们没有get_seconds
功能。
### Write your get_seconds function definition here:
def get_seconds(whatever)
seconds = whatever #think about this
return seconds
接下来,time_to_utc
没有返回语句,因此不会返回任何内容。
除了您报告的错误之外,还可以使用此功能
def time_from_utc(utc_offset, time):
return to_24_hour_clock(utc_offset + time)
time_from_utc
有两个名为utc_offset
和time
的参数,例如1(小时)和12:00(或者这是预先准备好的)。
它会使用to_24_hour_clock
的结果调用utc_offset + time
,我们的情况是下午1点,这将是24小时制的13:00。