Python Forum
Troubles with program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Troubles with program
#34
Oops, I didn't realize the numbers needed to be unique! The code as it currently stands could result in the same number being selected more than once. To ensure there are no duplicates, it might be best to first create a list of random numbers outside of your loop, and then just print each one sequentially within your loop. I think you probably know everything you need to do this based on your previous code. You'd want to do something like:

import random

numbers = ... # use sorted(), random.sample(), and range() on this line to create your list of 100 sequential random numbers

for i in range(100):
    letters=sorted(random.sample('abcdefgh',4))
    print(numbers[i]...) # print values from the numbers list sequentially along with your letters list generated within the loop
Try to fill in the blanks where the "..." is shown, and see what you can come up with.
Reply


Messages In This Thread
Troubles with program - by Harambe - May-27-2020, 10:38 PM
RE: Troubles with program - by Larz60+ - May-27-2020, 11:07 PM
RE: Troubles with program - by Harambe - May-27-2020, 11:09 PM
RE: Troubles with program - by Larz60+ - May-27-2020, 11:17 PM
RE: Troubles with program - by Harambe - May-27-2020, 11:25 PM
RE: Troubles with program - by deanhystad - May-28-2020, 05:12 AM
RE: Troubles with program - by perfringo - May-28-2020, 06:20 AM
RE: Troubles with program - by Knight18 - May-28-2020, 06:34 AM
RE: Troubles with program - by Harambe - May-28-2020, 09:25 AM
RE: Troubles with program - by buran - May-28-2020, 09:34 AM
RE: Troubles with program - by Harambe - May-28-2020, 10:04 AM
RE: Troubles with program - by pyzyx3qwerty - May-28-2020, 10:16 AM
RE: Troubles with program - by Harambe - May-28-2020, 10:25 AM
RE: Troubles with program - by pyzyx3qwerty - May-28-2020, 10:59 AM
RE: Troubles with program - by Harambe - May-28-2020, 11:04 AM
RE: Troubles with program - by pyzyx3qwerty - May-28-2020, 11:13 AM
RE: Troubles with program - by Harambe - May-28-2020, 11:49 AM
RE: Troubles with program - by GOTO10 - May-28-2020, 12:14 PM
RE: Troubles with program - by pyzyx3qwerty - May-28-2020, 12:23 PM
RE: Troubles with program - by Harambe - May-28-2020, 12:52 PM
RE: Troubles with program - by pyzyx3qwerty - May-28-2020, 01:09 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 01:09 PM
RE: Troubles with program - by BitPythoner - May-28-2020, 01:12 PM
RE: Troubles with program - by Harambe - May-28-2020, 01:27 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 01:29 PM
RE: Troubles with program - by Harambe - May-28-2020, 01:32 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 01:36 PM
RE: Troubles with program - by Harambe - May-28-2020, 01:40 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 01:41 PM
RE: Troubles with program - by Harambe - May-28-2020, 01:44 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 01:45 PM
RE: Troubles with program - by Harambe - May-28-2020, 01:58 PM
RE: Troubles with program - by pyzyx3qwerty - May-28-2020, 02:26 PM
RE: Troubles with program - by Harambe - May-28-2020, 04:37 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 05:05 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 02:29 PM
RE: Troubles with program - by Harambe - May-28-2020, 05:05 PM
RE: Troubles with program - by GOTO10 - May-28-2020, 05:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a list troubles giveen 7 4,084 Jan-11-2019, 08:05 PM
Last Post: giveen
  Troubles on how to use Open CV knowledge1st 1 2,586 May-23-2018, 05:57 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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