Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generating numbers
#1
Hi
Im trying to generate number sequence who i want to look like this.

Quote:7-1-1234
8-2
9-3
10-4
11-5
12-6
13-7-1234

But instead it looks like this.
Quote:7-1-1234






13-7-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?
Reply
#2
Move one parenthese
print("{}-{}".format(value3 + parts, parts+1) + ('-{}\n'.format(value1) if parts in [0, value2 - 1] else ''))
Reply
#3
(Dec-01-2019, 11:11 AM)Gribouillis Wrote: Move one parenthese
print("{}-{}".format(value3 + parts, parts+1) + ('-{}\n'.format(value1) if parts in [0, value2 - 1] else ''))

Tnx for your answer. It works but i get a gap between the first and second rows.

Quote:7-1-1234

8-2
9-3
10-4
11-5
12-6
13-7-1234

And im geting this when i try to insert it in to text entry in my tkinter app.

Quote:7-1-1234
8-29-310-411-512-613-7-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 ''))
Reply
#4
Ok now im close maybe. I got it to generate something like this.

Quote:7-1-1234

8-2-

9-3-

10-4-

11-5-

12-6-

13-7-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

8-2

9-3

10-4

11-5

12-6

13-7-1234
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I name a list while generating numbers on the fly? Pleiades 6 3,226 Dec-03-2019, 05:47 PM
Last Post: jefsummers
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,661 May-09-2019, 12:19 PM
Last Post: Pleiades
  About generating N integer numbers without repetition Otbredbaron 3 3,833 Jan-30-2018, 12:08 PM
Last Post: Otbredbaron
  prime numbers generator is generating non prime numbers? ixaM 2 4,415 Dec-18-2016, 01:35 PM
Last Post: ixaM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020