Thursday, December 18, 2014

1.3.8 While Loops

While Loops

Number Guesser

Conclusion: 

1.) If you change between 1 and 20 from the previous program to between 1 and 6000, how many will you need to guarantee that you have the right answer?
           To guarantee that you have the right answer you will need 6000 because there are 6000 numbers one can guess so someone could guess every number except the right one, then the last guess would be the right one, which would add up to 600 guesses.

2.) Describe the difference between a while loop and a for loop.
            A for loop repeats a block of code for every time an event occurs. A while loop repeats a block of code so long as a condition remains true.

Friday, December 12, 2014

1.3.7 Loops

            Loops




           Lottery Ticket













             Hangman 














Conclusion

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 "unrolled loops" has its disadvantages during development because it is very tedious work, boring, and its just really really inefficient. It would be a pain to change an unrolled loop of "for i range(10) to "for i range(1000)".


2.      Name a large collection across which you might iterate.

            A department store computer could iterate over a list of items in stock.


3.      What is the relationship between iteration and the analysis of a large set of data?

          Iteration reads and changes information about each item, where as data analysis only reads from them to get statistics. However both iteration and data analysis deal with large amounts of data.



Monday, December 8, 2014

1.3.6 Tuples and Lists

1.3.6 Tuples and Lists
Conclusion
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?
      
 The ways that a,b, and c are different is that a is a string, b is a tuple, and finally c is a list.


2.      Why do computer programming languages almost always have a variety of variable types? 

          Not everything can be answered with one variable type. For example, some situations require a true or flase statement whereas others require a number. These variables would have to be two different types.

3.Why can't everything be represented with an integer?

           Not all situations require an integer. Some require a true or false. Others require a float in that of a decimal places need to be accounted for.

Thursday, December 4, 2014

1.3.5 Strings

Strings

Tweet

Conclusion:
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 charactres in that sentence. Yes because unicode uses four bytes per character, and ASCII uses one byte per character. Unicode offers a wider range of characters.

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.

In []: a = 'one string'
In []: b = 'another'
In []: c = a[:3] + ' and ' + b
In []: print(c[6:10])

012345678901234           
one_and_another
dan
What occurs in this memory when this code is executed is first a equals the phrase ' one string '. Then, b equals the word another. Next c is going to equal the first 3 characters of a plus ' and' plus b. So c is going to end up equalling ' one _and_ another '. Lastly, the code is going to print the 6th character to the 10th character in c. But its not going to include the 6th and 10th character.