Python 返回带字符串的函数

Python 返回带字符串的函数,python,Python,说明:编写一个程序,以英尺和英寸为单位接收两块织物的长度(作为整数),并以字符串形式返回总长度,格式为:英尺:7英寸:3(使用链接到网站 总数(5,11,1,4)→ '英尺:7英寸:3' 总数(0,1,1,4)→ '英尺:1英寸:5' 总数(3,6,2,6)→ '英尺:6英寸:0' 代码: 我的返回没有得到我需要的输出…我不知道还能做什么,因为它在另一个网站上工作。它表示无效语法错误,但如果我删除导致它显示的“f” 'Feet: {feet+additional_f} Inches: {inch

说明:编写一个程序,以英尺和英寸为单位接收两块织物的长度(作为整数),并以字符串形式返回总长度,格式为:英尺:7英寸:3(使用链接到网站

总数(5,11,1,4)→ '英尺:7英寸:3'

总数(0,1,1,4)→ '英尺:1英寸:5'

总数(3,6,2,6)→ '英尺:6英寸:0'

代码:

我的返回没有得到我需要的输出…我不知道还能做什么,因为它在另一个网站上工作。它表示无效语法错误,但如果我删除导致它显示的“f”

'Feet: {feet+additional_f} Inches: {inches}'

有人知道如何修复它吗?

因为您返回的是
f'Feet:{Feet+额外的{f}英寸:{Inches}
,所以您必须
将它打印出来,然后您将看到结果

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)

我运行了你的代码并得到了正确的输出你使用python 3.7吗?@Mike67你在网站上运行过吗?@yhenon我在chromebook上,我必须使用repl.it,所以我不知道。明白了-使用
total='Feet:'+str(Feet+additional_f)+'Inches:'+str(Inches)
所有测试都通过了这个更改。
total = 'Feet: '+ str(feet+additional_f) + ' Inches: '+ str(inches)