1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 from math import pi
4 print ('%10f'%pi)
5 print ('%-10f' % pi)
6 print ('%010f' % pi)
7 print ('% -010f' % pi)
8 print ('%0-10f' % pi)
9 print ('% 10.2f' % pi)
10 print ('%+10.2f' % pi)
11 print ('%-010.2f' % pi)
12 print ('%10.2f'%pi)
13 print ('%010.2f' % pi)
14 print ('%.2f'%pi)
15 print ('%.*s'%(5,'Guido van Rossum'))
1 3.141593
2 3.141593
3 003.141593
4 3.141593
5 3.141593
6 3.14
7 +3.14
8 3.14
9 3.14
10 0000003.14
11 3.14
12 Guido
1 #!/usr/bin/env python
2 # -*- coding:utf-8 -*-
3 width=raw_input("Please enter width: ")
4 price_width=10
5 item_width=int(width)-price_width
6 header_format='%-*s%*s'
7 format='%-*s%*.2f'
8 #s=['=']
9 print '=' * int(width)
10 print header_format % (item_width,'Item',price_width,'Price')
11 print '+' * int(item_width),
12 print '-' * int(price_width)
13 print format % (item_width,'Apples',price_width,0.4)
14 print format % (item_width,'Pears',price_width,0.5)
15 print format % (item_width,'Cantaloupes',price_width,1.92)
16 print format % (item_width,'Dried Apricots(16 0z.)',price_width,8)
17 print format % (item_width,'Pruned(4 lbs',price_width,12)
18 print '=' * int(width)
1 Please enter width: 35
2 ===================================
3 Item Price
4 +++++++++++++++++++++++++ ----------
5 Apples 0.40
6 Pears 0.50
7 Cantaloupes 1.92
8 Dried Apricots(16 0z.) 8.00
9 Pruned(4 lbs 12.00
10 ===================================