0

说明:编写一个程序,接收以英尺和英寸为单位的两块织物的长度(作为整数),并以字符串形式返回总和,格式为:英尺:7 英寸:3(使用https://codingbat链接到网站.com/prob/p267045?parent=/home/bryce.hulett@hotmail.com

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

总计(0、1、1、4)→“英尺:1 英寸:5”

总计(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}'

有谁知道如何修理它?

4

1 回答 1

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)
于 2020-11-01T03:51:28.637 回答