python - How add 2 arrays? -


i add array score array score2 have result. function print score has problem. have idea concerning problem? please. should create empty array ? example array score3?

thank lot help. because student it's exercise school.

more info create function attributes scores smallest biggest. (first round) example: karim benzema has 2 scores thierry henry has 4 scores lionel messi has 6 scores

then create function attributes still scores smallest biggest (second round)
example: thierry henry has 2 scores karim benzema has 4 scores lionel messi has 6 scores

here result: karim benzema 4 scores thierry henry 6 scores lionel messi 12 scores

name = []; goal = []; point = [2,4,6] score = [] goal2 = [] score2 = []   def demand(nb):   in range(nb):     name.append(str(input("enter name n° " + str(i+1) +  " please : ")))     while true:       var = int(input("enter number of goal (10-100) " + name[i] +  ": "));       if var >=10 , var <=100: break       print(var, " error ! ")     goal.append(var)    return name, goal;    def tri1(name, goal):   in range(len(name)-1,0,-1):     j in range(i):       if name[j+1] < name[j]:         temponame = name[j]         tempogoal = goal[j]         name[j] = name[j+1]         goal[j] = goal[j+1]         name[j+1] = temponame;         goal[j+1] = tempogoal    return name, goal   def printtri1(name, goal):   in range(len(name)):     print(name[i] + " \t " + str(goal[i]));    def printpoint1(name, point, score):   in range(len(name)):     print("name : " + name[i] + " score of " + str(point[i]) + " : " + str(goal[i]) + " goals. ")   score.append(point[i])    def demand2(nb):   in range(nb):     print("name " + name[i] + " - : ");     while true:       var = int(input("enter number of goal (10-100) " + name[i] +  ": "));       if var >=10 , var <=100: break       print(var, " error ! ")     goal2.append(var)    return name, goal, goal2   def tris2(name, goal, goal2):     in range(len(name)-1,0,-1):       j in range(i):         k in range(j):            if name[k+1] < name[k]:              temponame = name[k]              tempogoal = goal[k]              tempogoal2 = goal2[k]              name[k] = name[k+1]              goal[k] = goal[k+1]              goal2[k] = goal2[k+1]              name[k+1] = temponame;              goal[k+1] = tempogoal;              goal2[k+1] = tempogoal2;   def printtri2(name, goal, goal2):   in range(len(name)):     print(name[i] + " \t " + str(goal[i]) + str(goal2[i]) );    def printpoint2(name, point, score2):   in range(len(name)):     print("name : " + name[i] + " score of  " + str(point[i]) + " : " + str(goal2[i]) + " goals. ")   score2.append(point[i])   def printscore(attaquant, score, score2):     in range( len( attaquant) ):         print(attaquant[ ] + "\t" + str( score[i]) + "\t" + str( score2[i]))      name, goal = demand(3); tri1(goal, name); printtri1(name, goal) printpoint1(name, point, score)   name, goal, goal2 = demand2(3) tris2(goal2, name, goal) printpoint2(name, point, score2) printscore(score, score2) 

if right, want "concatenate" 2 arrays together: name , score without using dictionaries/in-built functions. here's how that:

name = ["karim benzema", "thierry henry", "lionel messi"]; score1 = [12, 5, 20]; score2 = [8, 2, 10];  # prepare result array result =  [];  # loop 0 len(name,score) - 1 in range(len(name)):    # append result string concatenation of name[i] , score[i]   result.append(name[i] + " " + str(score1[i]+score2[i]));  # display result print(result) 

edit: following code works:

def printscore(name, score1, score2):   result = [];   in range(len(name)):     result.append(name[i] + " " + str(score1[i] + score2[i]));   print(result)   name = ["karim benzema", "thierry henry", "lionel messi"]; score1 = [12, 5, 20]; score2 = [8, 2, 10]; printscore(name, score1,score2) 

full code, see here


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -