Python Forum
Random nr. no repetition & printing multiple lines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random nr. no repetition & printing multiple lines
#6
Ok the changes you suggested:

import random
 
mylist = []
 
for i in range(10):
    x = random.randint (1,30)
    if x not in mylist: mylist.append(x)
 
for x in mylist:
    print(mylist)
This is the output:
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]
[16, 4, 11, 15, 13, 14, 30, 18, 1]

Is there something that i miss?
Reply


Messages In This Thread
RE: Random nr. no repetition & printing multiple lines - by Joey - Feb-05-2020, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write the condition for deleting multiple lines? Lky 3 1,210 Jul-10-2022, 02:28 PM
Last Post: Lky
  Delete multiple lines from txt file Lky 6 2,401 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  python-docx: preserve formatting when printing lines Tmagpy 4 2,215 Jul-09-2022, 01:15 AM
Last Post: Tmagpy
  Display table field on multiple lines, 'wordwrap' 3python 0 1,822 Aug-06-2021, 08:17 PM
Last Post: 3python
  pulling multiple lines from a txt IceJJFish69 3 2,644 Apr-26-2021, 05:56 PM
Last Post: snippsat
  Way to avoid repetition? Tuxedo 5 2,966 Feb-16-2021, 08:02 PM
Last Post: Tuxedo
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 6,120 Aug-10-2020, 11:01 PM
Last Post: medatib531
  question about you want repetition this task loczeq 6 3,426 Mar-05-2020, 08:35 PM
Last Post: loczeq
  print python json dump onto multiple lines lhailey 2 20,099 Mar-02-2020, 12:47 PM
Last Post: vishalhule
  how to insert # to multiple lines? hkfatasy 1 2,949 Dec-22-2019, 01:51 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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