python练习题

来源:互联网 发布:守望先锋优化补丁 编辑:程序博客网 时间:2024/05/16 00:57
from builtins import formatwidth = int(input('请输入表格的宽度:'))  price_width = 10  item_width = width - price_width  header_format = '%-*s%*s'  format = '%-*s%*.2f'  print ('='*width)  #打印表头  print (header_format %(item_width,'项目',price_width,'价格'))  print ('-' * width)  print (format % (item_width,'苹果',price_width,6.0))  print (format % (item_width,'桔子',price_width,3.2))  print (format % (item_width,'香蕉',price_width,2.5))  print (format % (item_width,'葡萄',price_width,14.8))  print (format % (item_width,'红提',price_width,15))  print (format % (item_width,'西瓜',price_width,1.5))  print ('='*width)  
原创粉丝点击