使用return语句摆脱多余的空间

时间:2019-11-19 07:44:37

标签: python python-3.x

当我说有12个苹果时,在句号之前有一个空格。有人知道如何腾出空间吗?

def main():
  apples = int(input("Enter the number of apples: "))
  time = float(input("Enter how much time in hours there is to find apples: "))
  print("There are", apples, "apples,", ENOUGH(apples), OBJECTIVE(time))
def ENOUGH(apples):
  if apples == 12:
    return("which is enough")
  elif apples < 12:
    return("which is not enough")
  elif apples > 12:
    return("which is too many")
def OBJECTIVE(time):
  if time >= 2:
    return TIME(time)
  elif time < 2:
    return(".")
def TIME(apples):
  if apples < 12:
    return(', but we have time to get more.')
  elif apples > 12:
    return(', but we have time to put some back.')
  elif apples == 12:
    return(".")
main()

1 个答案:

答案 0 :(得分:0)

使用字符串连接,例如

print("There are", apples, "apples,", ENOUGH(apples)+OBJECTIVE(time))

这将使分隔符(空格)停止在最后两个参数之间。