Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How add 2 arrays?
#1
Hello all,

I am a student who learns Python. I should in my exercise create several functions (only) and manipulate several arrays.

 

1) first step:

Create a function whose enters 3 soccer player (names) and  whose enters the number of goals also [OK]

 

Example:

Thierry Henry => 20 goals

Lionel Messi   => 32 goals

Karim Benzema => 16 goals

 

2) second step:

Create a function whose sorts goals from smallest to biggest  [OK]

 

3) third step:

Create a function whose prints the name of the soccer player and the number of goals. [OK]

 

Example:

Karim Benzema => 16 goals

Thierry Henry => 20 goals

Lionel Messi   => 32 goals

 

 

4) fourth step:

Create a function whose attributes scores from smallest to biggest.     [OK]

 

Example:

Karim Benzema has 2 scores

Thierry Henry has 4 scores

Lionel Messi has  6 scores

 

5) fifth step:

Create a function whose enters still goals (second rounds) with always the same soccer player.  [OK]

Example

Karim Benzema => 10 goals

Thierry Henry => 8  goals

Lionel Messi   => 14  goals

 

6) Sixth step:

Create a function whose sorts still goals.    [OK]

 

7) Seventh step:

Create a function whose prints the name of the soccer player and the number of goals (first round and second rounds) . [OK]

 

8)Eighth step:

Create a function whose attributes still scores from smallest to biggest (second round) [OK]

 

Example:

Thierry Henry has 2 scores

Karim Benzema has 4 scores

Lionel Messi has  6 scores

 

9) Ninth step:

I would like to create a function whose will add the array score1 with the array score2.

Here is the result:

Karim Benzema 4 scores

Thierry Henry  6 scores

Lionel Messi 12 scores

I don’t should to use of dictionary !!!

Thank you a lot for your help…
 

name = ;
goal = ;
point = [2,4,6]
score =
goal2 =
score2 =
result =


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(name, score, score2, result):
for i in range( len( name) ):
result.append(name[i] + " " + str(score[i]+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(name, score, score2, result)
[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
Reply


Messages In This Thread
How add 2 arrays? - by Augustin1340 - Jul-26-2017, 11:36 AM
RE: How add 2 arrays? - by micseydel - Jul-26-2017, 03:43 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-26-2017, 05:51 PM
RE: How add 2 arrays? - by sparkz_alot - Jul-26-2017, 05:59 PM
RE: How add 2 arrays? - by nilamo - Jul-26-2017, 06:01 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-26-2017, 06:25 PM
RE: How add 2 arrays? - by nilamo - Jul-26-2017, 06:39 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-27-2017, 07:37 AM
RE: How add 2 arrays? - by sparkz_alot - Jul-27-2017, 12:59 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-27-2017, 01:56 PM
RE: How add 2 arrays? - by nilamo - Jul-27-2017, 03:50 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-27-2017, 06:36 PM
RE: How add 2 arrays? - by nilamo - Jul-27-2017, 06:58 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-27-2017, 07:56 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-30-2017, 11:11 PM
RE: How add 2 arrays? - by nilamo - Jul-31-2017, 06:45 PM
RE: How add 2 arrays? - by Augustin1340 - Jul-31-2017, 09:39 PM
RE: How add 2 arrays? - by nilamo - Aug-01-2017, 02:34 AM
RE: How add 2 arrays? - by Augustin1340 - Aug-01-2017, 07:23 AM
Arrays and functions - by Augustin1340 - Jul-27-2017, 07:45 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020