我想添加與數組score2數組得分的結果。 我的功能打印分數有問題。你有關於我的問題的想法嗎?請。我應該創建另一個空陣列嗎?例如一個數組score3?如何添加2個數組?
非常感謝您的幫助。因爲我是學生,這是學校的練習。
更多信息 創建一個功能,其屬性從最小到最大。 (第一輪) 實施例: 澤馬具有分數 亨利具有分數 梅西具有6個分數
然後 創建其屬性仍然分數從最小到最大(第二輪)
實施例的功能: 亨利具有分數 澤馬具有分數 梅西具有6個分數
下面是結果: 澤馬分數 亨利6個分數 個梅西12分
name = [];
goal = [];
point = [2,4,6]
score = []
goal2 = []
score2 = []
def demand(nb):
for i in range(nb):
name.append(str(input("Enter name n° " + str(i+1) + " please : ")))
while True:
var = int(input("Enter the number of goal (10-100) for " + name[i] + ": "));
if var >=10 and var <=100: break
print(var, " error ! ")
goal.append(var)
return name, goal;
def tri1(name, goal):
for i in range(len(name)-1,0,-1):
for 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):
for i in range(len(name)):
print(name[i] + " \t " + str(goal[i]));
def printPoint1(name, point, score):
for i in range(len(name)):
print("Name : " + name[i] + " Your score is of " + str(point[i]) + " : " + str(goal[i]) + " goals. ")
score.append(point[i])
def demand2(nb):
for i in range(nb):
print("Name " + name[i] + " - : ");
while True:
var = int(input("Enter the number of goal (10-100) for " + name[i] + ": "));
if var >=10 and var <=100: break
print(var, " error ! ")
goal2.append(var)
return name, goal, goal2
def Tris2(name, goal, goal2):
for i in range(len(name)-1,0,-1):
for j in range(i):
for 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):
for i in range(len(name)):
print(name[i] + " \t " + str(goal[i]) + str(goal2[i]));
def printPoint2(name, point, score2):
for i in range(len(name)):
print("Name : " + name[i] + " Your score is of " + str(point[i]) + " : " + str(goal2[i]) + " goals. ")
score2.append(point[i])
def printScore(attaquant, score, score2):
for i in range(len(attaquant)):
print(attaquant[ i ] + "\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)
所以,你有一個數組名稱和其他與分數,並你想分別與這兩個合併的數組? –
目前還不清楚你想要什麼 – Ivan
你好@ Ubdus薩馬德,是的請 – tamzoro