当我将此内容提交给zyBooks进行评分时,它似乎不起作用。但是,它确实在开发方面

时间:2019-07-17 22:00:43

标签: python data-visualization

我的输出与预期的输出不匹配。

我尝试重新排列代码以尝试使事情与预期输出匹配。但是,那也不起作用。

def head(title, clm1, clm2):
  print ('You entered:', title)
  print("\n".rstrip("\n"))
  print ('You entered:', clm1)
  print("\n".rstrip("\n"))
  print ('You entered:', clm2)
  return title, clm1, clm2
def print_data_point(data_point):

  while True:
    if data_point == '-1':
      break
    elif ',' not in data_point:
      print('Error: No comma in string.')
      print("\n".rstrip("\n"))
    else:
      if len(data_point.split(',')) > 2:
        print ('Error: Too many commas in input.')
        print("\n".rstrip("\n"))
      else:
        if not(data_point.split()[-1].isnumeric()):
          print('Error: Comma not followed by an integer')
          print("\n".rstrip("\n"))
        else:
          list=data_point.split(',') 
          print('Data string:',list[0])
          print('Data integer:',list[1])
    return data_point
if __name__ == '__main__':
  title = input('Enter a title for the data:\n')
  clm1 = input('Enter the column 1 header:\n')
  clm2 = input('Enter the column 2 header:\n')
  title, clm1, clm2 = head(title, clm1, clm2)
  data_point = input('Enter a data point (-1 to stop input):\n')
  data_point = print_data_point(data_point)
  print('%33s'%title)
  print('%-*s|%-*s'%(20,clm1,23,clm2))
  print('--------------------------------------------')
  list=data_point.split(',')
  print('%-*s|%*s'%(20,list[0],23,list[1]))

创作的小说数量 空白 空白 -1

当前输出

Enter a title for the data:
Enter the column 1 header:
Enter the column 2 header:
You entered: Number of Novels Authored

预期产量

Enter a title for the data:
You entered: Number of Novels Authored

1 个答案:

答案 0 :(得分:0)

尝试如下重构您的.foo()代码,

main