Problem 2
Question:
Display the first 20 powers of 2,i.e.{2,4,8,...}.
Answer:
(a)
There are several ways to do this. Simplest is to use lists, using the fact that , and Range gives you a list of integers.
(b)
Another way is with a looping construction. We haven't talked about loop constructions yet, but they're coming up soon - and I saw that several people had tried to use them for this problem. This one generates a list by evaluating the for i=1 to 20.
(c)
And finally here's one that loops from i=1 to 20, printing out each .
The downside of this kind of construction is that printing the result doesn't save it for another round of manipulation.
Created by Mathematica (September 13, 2004)