Tuesday, December 16, 2014

1.3.7 ForLoops

1.3.7 ForLoops







1.       Sometimes code using an iterative loop can be written without a loop, simply repeating the iterated code over and over as separate lines in the program. Explain the disadvantages of developing a program this way.
 Using this method, the code is shorter that if you were to just repeat the code over and over. Also, the code is easier to understand if other people were to look at it.


2.      Name a large collection across which you might iterate.
 You might iterate and large amount of data, such as a long list of names, or the stock in the store.


3.      What is the relationship between iteration and the analysis of a large set of data?
Iteration changes the data as needed, but the analysis of data only looks over the data.


Wednesday, December 10, 2014

Activity 1.3.6 Tuples and Lists

Tuples and Lists
1. Consider a string, tuple, and list of characters.

In []: a = 'acbde'
In []: b = ('a', 'b', 'c', 'd', 'e')
In []: c = ['a', 'b', 'c', 'd', 'e']
The values of a[3], b[3], and c[3] are all the same. In what ways are a, b, and c different? 
A is a string, B is a tuple and C is a list. Strings are just something you type in and it can be anything as long as you have a ' before and after the string. a tuple is immutable, which means the values cannot be changed. A list can be changed, inserted, or deleted and lists are mutable.
2.  Why do computer programming languages almost always have a variety of variable types?  
Different situations call for a different usage of variable types. If you were doing any math, you wouldn't use a tuple because the values wouldn't change.
3.  Why can't everything be represented with an integer?
Everything can't be represented with an integer because tuples cannot take integeres, even though everything is stored as 1s and 0s. Some things you want to do require a string, like printing back a message, and that would be difficult trying to print a message only using 1s and 0s.

Thursday, December 4, 2014

Activity 1.3.5:Strings



Activity 1.3.5:Strings



1.       How many characters are in this sentence? Does it matter whether Python is storing the string as one byte per character or four bytes per character?
There are 41 characters in that sentence. it doesn't matters if Python stores a string as 1 byte or 4 bytes as.

2.      This question asks you about something you have not learned. In fact, the question is asking about details that go beyond what you will learn in this course. However, wondering what is going on at a lower level of abstraction – and talking about it – can be a useful strategy when learning about computing.


Describe what you think occurs in memory when the following code is executed.
one and another
In []: a = 'one string'
In []: b = 'another'
In []: c = a[:3] + ' and ' + b
In []: print(c[6:10])

When this code is executed it will print 'd an' because of slicing. Slicing is when it takes a specific area of a desired string, and you can combine different strings to get a result.