0

Can you help me?

what syntax and loop would I use to iterate through the array to calculate the average number of letters per name?

17th Jul 2019, 6:34 AM
Jarom
Jarom - avatar
3 Antworten
0
you can use for
17th Jul 2019, 6:47 AM
Taste
Taste - avatar
0
You could do it by taking a name as input, storing them in an array, then write a loop that, for reach element in the array, adds the length of each element to another variable, which is then divided by the length of the array. Pseudocode: arrayOfNames = [] inputName as input add inputName to array averageName method: lengthOfArray = 0 lengthOfNames = 0 for each name in arrayOfNames: lengthOfArray += 1 lengthOfNames += len(name) averageOfNames = lengthOfNames / lengthOfArray print averageOfNames END of method averageName(inputName)
17th Jul 2019, 6:51 AM
Rincewind
Rincewind - avatar
0
Sorry, please see edit
17th Jul 2019, 6:53 AM
Rincewind
Rincewind - avatar