|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
width = input('Please enter width: ')
price_width = 10
item_width = width - price_width
header_format = '%-*s%*s'
format = '%-*s%*.2f'
print '=' * width
print header_format % (item_width, 'Item',price_width, 'price')
print '_' * width
print format % (item_width, 'Apple', price_width,0.4)
print format % (item_width, 'Pears', price_width,0.5)
print format % (item_width, 'Cantaloupes' , price_width,1.92)
print format % (item_width, 'Dried Apricots(16.oz.)' , price_width,8)
print format % (item_width, 'Prunes(4 lbs.)' , price_width,12)
print '=' * width
标红的部分怎么讲?看不太懂啊
-号是左对齐,*是在后面指定字符串宽度,.2f,保留小数点后2位
|
|