完整的初學者在這里。我正在嘗試讀取用戶的輸入并列印我使用回圈為其設定的相應含義,并且我看到它有問題,因為它沒有按我的預期作業。它適用于所有 3 個輸入作為 1,但如果做其他事情,事情看起來并不好。
options = [
["1. opt1", "2. opt2", "3. opt3"],
["1. opt1", "2. opt2", "3. opt3"],
["1. opt1", "2. opt2", "3. opt3", "4. opt4"]
]
meaning = [
[
["football"],
["basketball"],
["baseball"],
["Invalid"]
],
[
["water"],
["cocacola"],
["milk"],
["Invalid"]
],
[["human"],
["dogs"],
["cats"],
["robots"]
]
]
number = [1, 2, 3]
#question 1 and their options displayed here
number[0] = int(input(
"Type the number you see in front of the option you see above: "))
#question 2 and their options displayed here
number[0] = int(input(
"Type the number you see in front of the option you see above: "))
#question 3 and their options displayed herenumber[0] = int(input(
number[0] = int(input(
"Type the number you see in front of the option you see above: "))
i = 0
j = 0
for i in range(len(options)):
for j in range(len(meaning[i])):
if number[i] == i 1:
print(meaning[i][j])
break
else:
j = 1
i = 1
uj5u.com熱心網友回復:
如果您想回答第二個和第三個含義,請考慮給用戶
number[1] = int(input(...))
number[2] = int(input(...))
代替
number[0] = int(input(...))
uj5u.com熱心網友回復:
使用Константин Ушаков 的答案。并且:您在 for 回圈中失敗:嘗試使用:
if number[i] == j 1:
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/468167.html
上一篇:在回圈時將每個excel作業表分配給一個變數(使用openpyxl)并創建每個作業表的資料框
下一篇:讀取檔案并做數學
