Thursday, December 18, 2014

1.3.8 While loops


Conclusion 
1)     If you change between 1 and 20 from the previous program to between 1 and 6000, how many guesses will you need to guarantee that you have the right answer? Explain.
      You will need to have exactly 6000 guesses to assure that you undoubtably have the correct answer,
2)     Describe the difference between a while loop and a for loop.
      For loops repeats every time a specific event occurs, however while loops only repeat while a certian condition is true. The two can be used interchangibly based on your personal coding preferance.

Friday, December 12, 2014

1.3.7 For Loops


My code for the lottery and Mastermind:




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.

     By developing code without iterative loops in some scenarios may make writing the code much more simple, however it would not serve well in complex tasks. Having to rewrite the code several times over would take up much more space than needed, and would make the script much harder to read.

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

      Iteration is very in a variety of ways very useful. When having to loop, say 1000 times for a specific task it is much easier to just have a chunk of simple code that loops a program. Using a 'For' command or a 'While' loop accomplishes the task much faster, and with less work. 
3) What is the relationship between iteration and the analysis of a large set of data?
    Using Iteration you can very easily analyze two large sets of data, regardless of size and potentially compare, or contrast the two lists.

Thursday, December 4, 2014

1.3.6 Tuples and Lists

My Code For 15 and 16:

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' uses a single string to hold of the letters. 'b' uses a tuple to contain all of the                  letters. 'c' uses a list to contain all of the values


2.      Why do computer programming languages almost always have a variety of variable types? Why can't everything be represented with an integer?

                Representing everything with integers would make very large numbers. For                      example, representing the alphabet using binary, would leave 26 integers in a row to get        'Z'.

Tuesday, December 2, 2014

Conclusion Questions


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?

            42 Charactors. To me the amount of bytes per charactor is really unimportant. The only important thing is that the script functions properly.

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])
        
        I believe that the aboce code will pull out the first three characters of string 'a', add an ' and ' as well as placing string 'b' in the phrase. The new string: "C" will now read 'one and another'. The print will then type out charactor 6-10 from C saying: ''d an"

             

Code for "Tweet Eligability"

Task Description:
                A social media site offers a contest to write a humorous short paragraph. A constraint on the creative format: the entry must include a question, a quote, a compound sentence, and an exclamation. These would contain the characters ?, ", ,, and !, respectively.

Create a function how_eligible(essay) that returns 0 to 4, equal to the number of these four characters that the essay included. As pair programmers, generate ideas for how to solve this problem, strategize, and then code and test iteratively. 

My code: