Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将秒转换为小时,并在Python中获取输入和使用函数_Python - Fatal编程技术网

将秒转换为小时,并在Python中获取输入和使用函数

将秒转换为小时,并在Python中获取输入和使用函数,python,Python,代码:1-正在工作 def seconds_to_hours(seconds): hours = seconds / (60 * 60) return hours print(seconds_to_hours(5000)) seconds = input("Enter how many seconds convert to hours?: ") def seconds_to_hours(seconds): hours = seconds / (60

代码:1-正在工作

def seconds_to_hours(seconds):
    hours = seconds / (60 * 60)
    return hours
print(seconds_to_hours(5000))
seconds = input("Enter how many seconds convert to hours?: ")
def seconds_to_hours(seconds):
    hours = seconds / (60 * 60)
    return hours
print(seconds_to_hours)
代码:2-它不工作

def seconds_to_hours(seconds):
    hours = seconds / (60 * 60)
    return hours
print(seconds_to_hours(5000))
seconds = input("Enter how many seconds convert to hours?: ")
def seconds_to_hours(seconds):
    hours = seconds / (60 * 60)
    return hours
print(seconds_to_hours)
错误是:


如何解决此问题?

不要对获取输入的主参数
seconds
使用两次相同的名称,也不要将输入转换为
int

def seconds_to_hours(secs):
    return secs / (60 * 60)

seconds = int(input("Enter how many seconds convert to hours?: "))
print(seconds_to_hours(seconds))

谢谢您的快速回复。使用
作为参数有什么问题?它将屏蔽全局变量,这是一件好事。OP代码的主要问题是函数从未真正被调用,而不是变量名。不过对
int
的调用很好。@ggorlen无论您喜欢什么名称
secs
,但不相同,以避免误会这是更好的选择。我必须在输入中写入数据类型。