Difference between revisions of "Create an Array"

From CompSciWiki
Jump to: navigation, search
m (Added in missing periods to sentences and corrected the spelling of automatically.)
Line 2: Line 2:
 
ProblemName=Creating An Array
 
ProblemName=Creating An Array
 
|Problem=
 
|Problem=
Ten students' grade are 56%, 34%, 75%, 89%, 78%, 87%, 71%, 67%, 98%, 85%
+
Ten students' grade are 56%, 34%, 75%, 89%, 78%, 87%, 71%, 67%, 98%, 85%.
#Store their grades in an array as percent
+
#Store their grades in an array as percents.
#Convert to decimal and store them in an array
+
#Convert them to a decimal and store them in an array.
#Store their names in an array
+
#Store their names in an array.
|SideSectionTitle = Introducing Array
+
|SideSectionTitle = Introducing Arrays
 
|SideSection=
 
|SideSection=
  
 
|Solution=
 
|Solution=
Compare to java array, Python array is much easier. We don't need to declare the variables and we also don't need to indicate the type of each array. Because the type of an array is automatedly set when we assign the value. So the code will be
+
Compared to java arrays, Python arrays is much easier. We don't need to declare the variables and we also don't need to indicate the type of each array. Because the type of an array is automatically set when we assign the value. So the code will be:
  
 
{{CodeBlock|Code=
 
{{CodeBlock|Code=

Revision as of 19:13, 4 April 2012

Back to the Program-A-Day homepage

Problem

Ten students' grade 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 is much easier. We don't need to declare the variables and we also don't need to indicate the type of each array. Because 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