Python Forum
How can you make it simpler?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can you make it simpler?
#2
I'm not sure what the parameter "x" does - could you expand on that?

If you just want a 4 digit number with not repeating digits, you could try this:
def fourdigit():
  n = random.randint(1000, 9999) #randomly picks a 4 digit number
  digits = set(str(n)) #it creates a list of all of the characters in the numer
  if(len(digits) < len(str(n))): #set() ignore duplicates, so if there is a any duplicates the length of the list will be less than the original number
    return fourdigit() #therefore call it recursively until there is a value with no repeating digits
  return n #return the value
When I ran that over and over again I didn't see any values with any duplicate numbers.
Reply


Messages In This Thread
How can you make it simpler? - by bitcoin10mil - Aug-22-2020, 07:21 PM
RE: How can you make it simpler? - by DreamingInsanity - Aug-22-2020, 07:39 PM
RE: How can you make it simpler? - by bitcoin10mil - Aug-22-2020, 08:00 PM
RE: How can you make it simpler? - by bowlofred - Aug-22-2020, 08:31 PM
RE: How can you make it simpler? - by snippsat - Aug-22-2020, 08:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  i am looking for a simpler tokenizer Skaperen 7 3,606 Jul-29-2019, 05:31 PM
Last Post: Skaperen
  How to make this simpler. leoahum 7 3,806 Mar-11-2019, 01:57 PM
Last Post: leoahum

Forum Jump:

User Panel Messages

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