方向:编写一个程序,该程序接收以英尺和英寸为单位的两块织物的长度(作为整数),并以String的形式返回总计值:英尺:7英寸:3(使用{{ 3}}
total(5,11,1,4)→'英尺:7英寸:3'
total(0,1,1,4)→'英尺:1英寸:5'
total(3,6,2,6)→'英尺:6英寸:0'
代码:
def total(first_f,first_i,second_f,second_i):
inches = (first_i + second_i) % 12
feet = first_f + second_f
additional_f = (first_i + second_i) // 12
total = f'Feet: {feet+additional_f} Inches: {inches}'
return total
我的回报没有得到我需要的输出...我不确定该怎么办,因为它可以在其他网站上工作。它说无效的语法错误,但是如果我删除导致它的“ f”显示
'Feet: {feet+additional_f} Inches: {inches}'
有人知道如何解决吗?
答案 0 :(得分:0)
由于您返回了f'Feet: {feet+additional_f} Inches: {inches}'
,因此必须print
将其取出,您将看到结果
def total(first_f,first_i,second_f,second_i):
inches = (first_i + second_i) % 12
feet = first_f + second_f
additional_f = (first_i + second_i) // 12
total = f'Feet: {feet+additional_f} Inches: {inches}'
return total
print(total(5, 11, 1, 4))
结果:
Feet: 7 Inches: 3
如果对您不起作用,请使用以下方法更改total
:
total = 'Feet: '+ str(feet+additional_f) + ' Inches: '+ str(inches)