Index = str(getattr(entry,'index')).ljust(5)ĭescr = getattr(entry,'description').ljust(25) _menu.append(MenuEntry(2, 'Champagne Ham & Cheese', '$7.50')) Here's a quick example I whipped up using ljust, but don't stop here take a peek at the doc linked above and let your imagination go wild with string-formatting-freedom! from collections import namedtuple There are some super handy utilities for string formatting: ljust| rjust, for just this sort of thing. I'm very new to python, so explaining like I know nothing would be very helpful "A day at the supermarket tutorial" was not particularly helpful either. Here had a somewhat similar problem but the page did not help. Is there an easier way to solve my problem? Also as a side question when printing is there a way that "standardprice" variable applies to the first 7 elements and deluxe price applies to 8-12, rather than the crude way I have done it. Standardprice, standardprice, standardprice,deluxeprice,ĭeluxeprice,deluxeprice, deluxeprice, deluxeprice) """ % (standardprice, standardprice, standardprice, standardprice, Manually putting spaces does not seem like the most efficient way of going about my problem. Where the prices would "stick to the pizza name" and the names of pizzas 10 onwards were indented by one character. I have tried both dictionaries and lists but always resulted in this problem: 1 Hawaiian $7.50 I would then like the customer to be able to select different pizzas based on the number so that they don't have to type Hawaiian, they can instead type 1. I am new to python and would like to create a Pizza ordering system using python, that looks something like this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |