私はPythonにまったく慣れておらず、C++のこのコードスニペットを持っています:
do
{
cout << "Make sure the number of digits are exactly 12 : ";
cin >> input ;
} while((input.length()) != 12 );
この部分をPythonに変更するにはどうすればよいですか?私はこれまでこれを試しましたが、正しい構文またはロジックフローがわかりません。これは私が持っているものです:
while True:
print("Make sure the number of digits are exactly 12 : ")
input = raw_input()
check = len(input)
if check != 12
break
上記の部分は解決されました!
また、: inputである別のc++スニペットは文字列です
for (int i = 0; i < 12 ; i++)
{
code[i] = input.at(i) - '0';
}
この部分をPythonコードに変更する方法がわかりません
code[i] = input.at(i) - '0';
だから、私が抱えている問題は、配列を初期化する方法がわからないことです
int code[12] ;
私がこのコードを実行できるように、Pythonでどのようにすべきですか?与えられたように:
int code[12] ;
for (int i = 0; i < 12 ; i++)
{
code[i] = input.at(i) - '0';
}