私は最初のリストと一致するID番号をユーザーに入力させ、次の2つのリストからインデックスに一致する名前と料金を引いています。ただし、リスト内の従業員IDが見つかりません。私はさまざまなループを試しましたが、完全にエラーが出たり、 "0"の戻り値のような単一の数値を付けたり、最初のリストと一致しません。3つの別々のリストとパラレルアクセスでデータを保存する
これはクラス割り当てのためのものですが、私がしようとしているのと同様のクラスまたはオンラインの例は見つかりません。私はemployee_id_promptセクションでさまざまなループを試しましたが、動作させることができません。
誰かが入力を最初のリストと一致させ、2番目と3番目のリストから一致する値を返す方法について、いくつかのガイダンスを提供できますか?私は "employee_idで見つかった"、 "input_employee_id in employee_id"などの束を試しましたが、私が把握できないエラーを見つけ出しています。
SIZE = 10
employee_id = [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]
employee_name = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
employee_pay = [17.75, 18.23, 19.42, 20.00, 21.50, 22.34, 23.74, 24.68, 24.75, 25.00]
def check_int(prompt):
int_result = 0
while True:
try:
int_result = int(input(prompt))
except ValueError:
print("This is outside the range or invalid. Please enter again.")
continue
else:
break
return int_result
def employee_id_prompt():
input_employee_id = 0
found = False
index = 0
while True:
input_employee_id = check_int("Please enter your Employee ID number: ")
while found == False and index <= SIZE - 1:
if employee_id[index] == input_employee_id:
found = True
else:
index = index + 1
if found == True:
print("Welcome " + employee_name[index] + ". Your current pay rate is $", + employee_pay[index],
"an hour.")
break
else:
print("I'm sorry, that Employee ID number is not recognized.")
index = index + 1
employee_id_prompt()
これは実際には3つのリストにデータを構造化する良い方法ではありません。その場合は、何らかの種類のレコード(オブジェクト、タプル、namedtupleなど)を使用する必要があります。 –
あなたの疑問にお答えします(https://stackoverflow.com/help/someone-answers)。それはコミュニティを助ける。 –