Create an Array

From CompSciWiki
Revision as of 21:32, 4 April 2012 by EllaP (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

Ten students' grades are 56%, 34%, 75%, 89%, 78%, 87%, 71%, 67%, 98%, 85%.

  1. Store their grades in an array as percents.
  2. Convert them to a decimal and store them in an array.
  3. Store their names in an array.
 

Introducing Arrays

Solution

Compared to java arrays, Python arrays are much easier to work with. We don't need to declare the variables and we also don't need to indicate the type of each array - the type of an array is automatically set when we assign the value. So, the code will be:

 intArray = [56, 34, 75, 89, 78, 87, 71, 67, 98, 85]; 

Code

Solution Code

Back to the Program-A-Day homepage