2017-06-21 4 views
-1

を比較するので、私は12のリストの番号を持っています、私はそれを比較します、数字を持つ入力.Iは、リストと入力と比較して、入力と同様の番号を印刷します。どのように12のリストの

例:

入力:2 14 34 12 23 45

最初のリスト:[ "2"、 "14"、 "18"、 "28"、 "40"、 "48"]

出力2 14

私のコード:

w = raw_input("give number: ").split() 


a1 = ["2", "14", "18", "28","40", "48"] 
a2 = ["5", "9", "17", "21", "32", "49"] 
a3 = ["4", "18", "19", "30", "47", "49"] 
a4 = ["9", "15", "25", "28", "39", "43"] 
a5 = ["8", "11", "13", "25", "39", "48"] 
a6 = ["3", "12", "13", "14", "31", "33"] 
a7 = ["3", "12", "14", "23", "26", "45"] 
a8 = ["1", "10", "12", "15", "18", "37"] 
a9 = ["6", "7", "17", "38", "41", "44"] 
a10 = ["1", "7", "14", "17", "27", "35"] 
a11 = ["15", "23", "25", "26", "39", "48"] 
a12 = ["5", "12", "14", "30", "41", "48"] 

for a,b,c,d,e,f,g,h,i,j,k,l in zip(a1, b2, c3, d4, e5, f6, g7, h8, i9, j10, k11, l12): 
    if a in w : 
    print "(1)", a 
    elif b in w: 
    print "(2)", b 
    elif c in w: 
    print "(3)", c 
    elif d in w: 
    print "(4)", d 
    elif e in w: 
    print "(5)", e 
    elif f in w: 
    print "(6)", f 
    elif g in w: 
    print "(7)", g 
    elif h in w: 
    print "(8)", h 
    elif i in w: 
    print "(9)", i 
    elif j in w: 
    print "(10)", j 
    elif k in w: 
    print "(11)", k 
    else: 
    print "(12)", a 

これは私が来るものです....

所与の数:2 14 18 28

(1)2

(1)14

(1)18

(1)28

(8)40

(12)48

Can y私を助けてください....ありがとう!

答えて

1

人々が...(...ここにいない)この質問のために非常に感謝し、私を助けてそれら!!、私の問題の解決策は...私は解決策を書き、多分他の人がそれを必要とする...

bet_numbers = [ 
    {"2", "14", "18", "28","40", "48"}, 
    {"5", "9", "17", "21", "32", "49"}, 
    {"4", "18", "19", "30", "47", "49"}, 
    {"9", "15", "25", "28", "39", "43"}, 
    {"8", "11", "13", "25", "39", "48"}, #created set Lists with curly braces {} 
    {"3", "12", "13", "14", "31", "33"}, 
    {"3", "12", "14", "23", "26", "46"}, 
    {"1", "10", "12", "15", "18", "37"}, 
    {"6", "7", "17", "38", "41", "44"}, 
    {"1", "7", "14", "17", "27", "35"}, 
    {"15", "23", "25", "26", "39", "48"}, 
    {"5", "12", "14", "30", "41", "48"}, 
] 

drawn_numbers = set(raw_input("drawn numbers: ").split()) # build a set List 

for index, numbers in enumerate(bet_numbers, start=1): #with enumerate(),enumerate each List 
    correct = drawn_numbers & numbers #with "identifier" add Input + numbers = (1), (2),.... 
    if correct: #if statement without comparison because True is... 
     print "({}) {}".format(index, ', '.join(sorted(correct))) 

     #"({}) {}".format() = concatenate elements together . 
     # (index, ', '.join(sorted(correct))) = (1), (2),...sorted(correct),sorted the set lists output 
関連する問題