ループはこれに適しています。
raw_input
また、入力の代わりに使用することもできます。入力関数は、入力を解析して python として実行します。実行するpythonコマンドではなく、ある種のパスワードをユーザーに求めていると思います。
また、Python には i++ がありません。たとえば、i += 1 を使用します。
while ループの場合:
count = 0
while count < number_of_tries:
x=raw_input("some input prompt: ") # note raw_input
if len(x) < 5:
print("error message")
count += 1 #increase counter ### Note the different incrementor
elif len(x) >= 5:
break
if count >= number_of_tries:
# improper login
else:
# proper login
または for ループを使用:
for count in range(number_of_tries):
x=raw_input("some input prompt: ") # note raw_input
if len(x) < 5:
print("error message") # Notice the for loop will
elif len(x) >= 5: # increment your count variable *for* you ;)
break
if count >= number_of_tries-1: # Note the -1, for loops create
# improper login # a number range out of range(n)from 0,n-1
else:
# proper login