Difference between revisions of "Create an Array"
From CompSciWiki
m (Much easier.... (added in to work with since nothing else was specified)) |
m (Fixed a couple pluralization issues and some punctuation "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 ") |
||
Line 2: | Line 2: | ||
ProblemName=Creating An Array | ProblemName=Creating An Array | ||
|Problem= | |Problem= | ||
− | Ten students' | + | Ten students' grades are 56%, 34%, 75%, 89%, 78%, 87%, 71%, 67%, 98%, 85%. |
#Store their grades in an array as percents. | #Store their grades in an array as percents. | ||
#Convert them to a decimal and store them in an array. | #Convert them to a decimal and store them in an array. | ||
Line 10: | Line 10: | ||
|Solution= | |Solution= | ||
− | Compared to java arrays, Python arrays | + | 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: |
{{CodeBlock|Code= | {{CodeBlock|Code= |
Latest revision as of 21:32, 4 April 2012
Back to the Program-A-Day homepage
ProblemTen students' grades are 56%, 34%, 75%, 89%, 78%, 87%, 71%, 67%, 98%, 85%.
|
Introducing Arrays | |
---|---|---|
SolutionCompared 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 |