Print a formatted price list with a given width,formattedgiven,width = inpu
文章由Byrx.net分享于2019-03-23 06:03:03
Print a formatted price list with a given width,formattedgiven,width = inpu
width = input('Please enter width: ')price_width = 10item_width = width - price_widthheader_format = '%-*s%*s'format = '%-*s%*.2f'print '=' * widthprint header_format % (item_width, 'Item', price_width, 'Price')print '-' * widthprint format % (item_width, 'Apples', 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
相关内容
- Random Choice,randomchoice,import rando
- Simple Script That Counts the Words in sys.stdin,countssys.stdin,im
- Redirects prints to file,redirectsprints,x = 99y = 'H
- Redirecting Error Information,,import sys f
- Get user input,getuserinput,car = raw_i
- Introducing or,introducingor,print 'a' or
- Use # to start a comment,,SPAM = 1
- A comment on the same line as code,commentsame,print 2+2 #
- Dictionary for loop,dictionaryforloop,dict = {'x':
- Demonstrates global variables,,def read_glo
评论关闭