The first attempt is to receive it, but if you try it several times, it works X

Asked 2 years ago, Updated 2 years ago, 17 views

def Input_stdid():

stdId=""

 while 1:

  stdId_temp=0

  stdId_temp=input("Input stdudent id: ")

  for i in stdId_temp:

    if i in "0123456789" and len(stdId_temp)==8:

     stdId+=str(i)

    else:

     print("Wrong Input!")

     Input_stdid()


  break

Input_stdid()

We're working on a code that is a number and needs to be entered in 8 digits at the same time. There is no problem if you enter 8 digits in the first attempt, but if you enter 8 digits after entering 3 digits and 5 digits incorrectly at first, you will still get Wrong Input What's the problem?

python

2022-09-22 13:49

1 Answers

The same phenomenon as the question occurred because I misunderstood the reflexes and wrote them.

Perhaps the code the questioner wanted was as follows.

def Input_stdid():
    while True:
        numbers = input("Input stdudent id: ")
        if numbers.isnumeric() and len(numbers) == 8:
            return numbers
        else: 
            print("Wrong Input!")



2022-09-22 13:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.