mardi 31 octobre 2017

why the if-else does not loop

I find my prog's if-else does not loop, why does this happen and how can I fix it for checking?

for x in range(1,11):
    num = int(input("Please enter number "+str(x)+" [10 - 100]: "))

    if num >= 10 and num <= 100:
        inList.append(num)
    else:
        num = int(input("Please enter a valid number: "))

print(inList)

I found that the if-else only did once, so when I enter invalid num for the 2nd time, the prog still brings me to the next input procedure. What happen occurs?

Please enter number 1 [10 - 100]: 1
Please enter a valid number: 1
Please enter number 2 [10 - 100]:

Additionally, may I ask how can I check the inList for duplicated num, and then remove both of the num in the list?

Aucun commentaire:

Enregistrer un commentaire