![]() |
Generating numbers - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Generating numbers (/thread-22880.html) |
Generating numbers - darktitan - Dec-01-2019 Hi Im trying to generate number sequence who i want to look like this. Quote:7-1-1234 But instead it looks like this. Quote:7-1-1234 Here is my code. value1 = (1234) value2 = (7) value3 = (7) for parts in range(value2): print(("{}-{}".format(value3 + parts, parts+1) + '-{}\n'.format(value1) if parts in [0, value2 - 1] else ''))What am i missing and doing wrong? RE: Generating numbers - Gribouillis - Dec-01-2019 Move one parenthese print("{}-{}".format(value3 + parts, parts+1) + ('-{}\n'.format(value1) if parts in [0, value2 - 1] else '')) RE: Generating numbers - darktitan - Dec-01-2019 (Dec-01-2019, 11:11 AM)Gribouillis Wrote: Move one parenthese Tnx for your answer. It works but i get a gap between the first and second rows. Quote:7-1-1234 And im geting this when i try to insert it in to text entry in my tkinter app. Quote:7-1-1234 the code i use in tkinter app self.text_entry.insert(END,"{}-{}".format(value3 + parts, parts+1) + ('-{}\n'.format(value1) if parts in [0, value2 - 1] else '')) RE: Generating numbers - darktitan - Dec-01-2019 Ok now im close maybe. I got it to generate something like this. Quote:7-1-1234 With this code. But its still not right. value1 = (1234) value2 = (7) value3 = (7) for parts in range(value2): print("{}-{}".format(parts + value3, 1+parts) + '-{}\n'.format((value1) if parts in [0, value2 - 1] else ''))It should look like this. Quote:7-1-1234 |