向Python中的函数传递变量-TypeError:缺少必需的位置参数



我读过其他关于这个主题的帖子,但似乎都不适合我。我收到了一个错误:

类型错误:calcs((缺少3个必需的位置参数:"hrs"、"mins"one_answers"secs">

当我试图将这三个变量传递到calcs((中时:

该代码的目的是查看时钟上每个指针的度数(相对于12:00:00(。

def input_io():
input_time = input("Please enter the time following the HH:MM:SS format - be sure to include all colons and zeros needed. (e.g. 3:45:22 should be input as 03:45:22).")
bool_okinput = False
while bool_okinput != True:
if ':' not in input_time:
input_time = input("Missing Colon - Please check the format (HH:MM:SS) and re-enter the time.")
elif len(input_time) != 8:
input_time = input("Too Many/Too Few Characters - Please check the format (HH:MM:SS) and re-enter the time.")
else:
while bool_okinput != True:
input_time = input_time.split(":")
hrs = int(input_time[0])
mins = int(input_time[1])
secs = int(input_time[2])
if hrs > 12:
input_time = input(
"Hours is greater than 12 - Please check the format (HH:MM:SS) and re-enter the time.")
elif mins > 59:
input_time = input(
"Minutes is greater than 59 - Please check the format (HH:MM:SS) and re-enter the time.")
elif secs > 59:
input_time = input(
"Seconds is greater than 59 - Please check the format (HH:MM:SS) and re-enter the time.")
else:
bool_okinput = True
return [hrs, mins, secs]
inputs = input_io()
hrs = inputs[0]
mins = inputs[1]
secs = inputs[2]
def calcs(hrs, mins, secs):
degree_mult = 360/60
hrs_degree_mult = 360/12
if hrs == 12:
hrs = 1
degrees_secs = (secs * degree_mult)
degrees_mins = (mins * degree_mult)+(degrees_secs / 60)
degrees_hrs = (hrs * hrs_degree_mult)+(degrees_mins / 60)+(degrees_secs / (60^2))
return [degrees_hrs, degrees_mins, degrees_secs]
degrees = calcs()
degrees_hrs = degrees[0]
degrees_mins = degrees[1]
degrees_secs = degrees[2]
print(f"When the Time is: {hrs}:{mins}:{secs}")
print(f"Hour Hand Degrees: {degrees_hrs}")
print(f"Minute Hand Degrees: {degrees_mins}")
print(f"Second Hand Degrees: {degrees_secs}")

函数签名

def calcs(hrs, mins, secs):

"asks"在调用时会发送3个参数
线路

degrees = calcs()

调用所述函数CCD_ 1但不向其发送任何参数(空括号(。在随后的行中,您希望在调用时将计算出的变量发送给函数。

在不透露一切的情况下,这里有一个提示:

degrees = calcs(already_calculated_1, already_calculated_2, already_calculated_3)

calcs定义为接收3个参数,但您在此处调用它时没有任何参数:degrees = calcs()

相关内容

  • 没有找到相关文章

最新更新