看板 Python 關於我們 聯絡資訊
array = [1111,2222,3333,4444,5555,6666] def search(input): for item in array: if input == item: print "bingo" else: print "not yet" while True: keyin = raw_input() print search(keyin) ------------ 原本預期鍵入 2222 會產生 not yet bingo not yet not yet not yet not yet 但是卻產生 not yet not yet not yet not yet not yet not yet None 不知道是哪裡出問題..? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.1.134
IAMPF:型態問題~ 你list裡面的是int, 但你輸入的是string 07/01 14:08
IAMPF::把keyin轉成int或是把list裡改成['1111','2222',...] 07/01 14:09
bwtalk:原來如此~ 謝謝! 07/01 14:25
mikapauli:我覺得你search裡面應該是想用return吧? 07/02 10:19
DH:推樓上,不然最後的print有點多餘 07/03 08:07
bwtalk:喔對XD 07/03 11:20