samedi 26 septembre 2020

Test to see if each digit in a 9-digit integer is unique

How do I write an if statement to check if each number in a 9 digit number is unique? Clearly the if statement I wrote (see the bold line) isn't working. Would appreciate any help!!

x_raw = int(input("Please input a 9 digit number where no digit appears twice"))
x_nexthighestnumber = x_raw + 1
x = str(x_nexthighestnumber)

number = "incorrect"

while (x_nexthighestnumber < 999999999 and number == "incorrect"):
    **if (x[0] != x[1] != x[2] != x[3] != x[4] != x[5]!= x[6] != x[7] != x[8]):**
        number = "correct"
        print (x)
    else: 
        number = "incorrect"
        x_nexthighestnumber += 1

Aucun commentaire:

Enregistrer un commentaire