亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取列表中的索引

如何獲取列表中的索引

Helenr 2021-08-14 16:53:10
我將如何檢查是否找到該值并打印語法?我已經完成了所有代碼,但我的問題是我需要找到該值在列表中的位置。問題出在代碼的末尾。我將#blank 放在這些區域中,因為我不知道該放什么。這是我的代碼:list_of_scores = []count = 0for i in range(10):    grade = int(input("Enter a quiz score "))    list_of_scores.append(grade)for grade in list_of_scores:    while(count < 10):        print("The score at position[", count, "] = ", list_of_scores[count])        count = count + 1search_value = (int(input("Enter a number to search for: ")))***下面是我遇到麻煩的地方。我的代碼的頂部是它應該是怎樣的:while(count < len(list_of_scores)):    if(search_value) in list_of_scores:        print("The value of ", search_value, "is in the list at index",#blank)    else:        if search_value not in list_of_scores:            print(input("Sorry, this value isn't found. Please enter a new number:"))print("The location of this value is: ", list_of_scores)  
查看完整描述

1 回答

?
30秒到達戰場

TA貢獻1828條經驗 獲得超6個贊

使用index()來獲得項目的列表中的索引

print("The value of ", search_value, "is in the list at index",list_of_scores.index(search_value))



查看完整回答
反對 回復 2021-08-14
  • 1 回答
  • 0 關注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號