2017-07-13 67 views
0

我想創建2個數組。名稱的數組(空)和點(空)的表。函數中的兩個數組

我的問題是在我的情況。我想點必須遜色於20

這裏是我的代碼:

def demande(nb): 
    tabNom = [] 
    tabCote = [] 

    for i in range(nb): 
     tabNom.append(input("Entrer le " + str(i+1) + " nom svp : ")) 

     tabCote.append(input("Entrer le " + str(i+1) + " cote svp : ")) 

     if tabCote > 20: 

      print(input("Ressayez svp : ")) 


    return tabNom, tabCote 

nom, cote = demande(3) 

print(nom, cote) 

你有一個想法?請 謝謝很多

+0

你的意思是,在陣列中的值應低於20? – mvrma

+0

你在IF中怎麼做?檢查tabCote的長度是否小於20? ---->如果len(tabCote)> 20:???或者列表中的每個項目應小於20?因爲你說:「我想要的分數必須低於20分。」 – Wonka

回答

0
def demande(nb): 
    tabNom = [] 
    tabCote = [] 

    for i in range(nb): 
     tabNom.append(input("Entrer le " + str(i+1) + " nom svp : ")) 

     tabCote.append(input("Entrer le " + str(i+1) + " cote svp : ")) 

     if int(tabCote[i]) > 20: 

      print(input("Ressayez svp : ")) 


    return tabNom, tabCote 

nom, cote = demande(3) 
print(nom, cote) 

試試這一次

+0

非常感謝你!問題解決了......; – augustin1340

+0

我投票如何?我點擊箭頭(頂部)? – augustin1340

+0

仍然不接受ans @ augustin1340 – Exprator

0

你可以試試這個方法:

def demande(nb): 
    tabNom = [] 
    tabCote = [] 

    for i in range(nb): 
     tabNom.append(input("Entrer le " + str(i+1) + " nom svp : ")) 

     tabCote.append(input("Entrer le " + str(i+1) + " cote svp : ")) 

     if tabCote > 20: 

      print(input("Ressayez svp : ")) 


    return tabNom, tabCote 
if __name__ == '__main__': # main function 

    nom, cote = demande(3) 

    print(nom, cote) 
相關問題