有什么办法可以正确退货吗?

时间:2021-02-14 20:15:52

标签: python

Spyder 和其他 IDE 说它完全没问题,虽然它不能运行。

def tiempo_transferencia(tamano: float, ancho_banda: int)-> str:
tamano = 80
ancho_banda = 50
tamano_en_MB = round(tamano*1024,2)
ancho_banda_real= ancho_banda*0,125
tiempo = tamano_en_MB / ancho_banda_real
x =  tiempo // 3600
residuo1 = tiempo%3600
Y = residuo1// 60
residuo2 = residuo1%60
Z = residuo2 // 1
return "el archivo tardará" + str(x) + "horas" +str(Y)+ "minutos y" +str(Z) + "segundos en transferirse"

3 个答案:

答案 0 :(得分:0)

试试这个,把字符串放入变量并返回变量:

def tiempo_transferencia(tamano: float, ancho_banda: int)-> int:
     tamano = 80
     ancho_banda = 50
     tamano_en_MB = round(tamano*1024,2)
     ancho_banda_real= ancho_banda*0,125
     tiempo = tamano_en_MB / ancho_banda_real
     x =  tiempo // 3600
     residuo1 = tiempo%3600
     Y = residuo1// 60
     residuo2 = residuo1%60
     Z = residuo2 // 1
     variable_to_return = "el archivo tardará" + str(x) + "horas" +str(Y)+ "minutos y" +str(Z) + "segundos en transferirse"
    return variable_to_return

答案 1 :(得分:0)

  1. 确保代码在函数中缩进。
  2. 确保您正在调用函数,因为函数定义本身不会执行任何操作。例如:print(tiempo_transferencia(3.0, 5))
  3. 当您在函数内将变量设置为固定值时,为什么您的函数中还有参数?删除 tamano = 80ancho_banda = 50
  4. ancho_banda*0,125 无效,因为 Python 将其视为元组。这应该是一个单一的数字,因为您在下一行的某个分区中使用它。我不知道您在这一行中要做什么,因此除了将其设为没有逗号的单个整数之外,我无法提出改进建议。

这些更改应如下所示:

def tiempo_transferencia(tamano: float, ancho_banda: int)-> int:
    tamano_en_MB = round(tamano*1024,2)
    ancho_banda_real= ancho_banda*0,125 # Sort this line out
    tiempo = tamano_en_MB / ancho_banda_real
    x =  tiempo // 3600
    residuo1 = tiempo%3600
    Y = residuo1// 60
    residuo2 = residuo1%60
    Z = residuo2 // 1
    return "el archivo tardará" + str(x) + "horas" +str(Y)+ "minutos y" +str(Z) + 
    "segundos en transferirse"

print(tiempo_transferencia(3.0, 5)) # Example of function call

如果您在控制台中遇到错误,请确保将其包含在您的问题中。

答案 2 :(得分:0)

也许在下面一行:

ancho_banda_real= ancho_banda*0,125

代码ancho_banda*0,125被认为是一个元组,所以如果你想把ancho_banda乘以十进制0.125,试着用0.125代替0,125。

相关问题