Wednesday, December 17, 2014

1.3.8

1.3.8 While Loops
Number Guesser

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.

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 6000 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.

Sunday, December 14, 2014

1.3.7

1.3.7 For Loops

Mastermind


Lottery Ticket



Questions:
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.


If a program is developed this way, it will take up much more space, be more time consuming, and take longer to run than if the code were just created with a loop.

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

A collection of music, perhaps to make sure two directories have the same exact songs and to fill the ones that are missing from each other. my collection has about 900 songs, and the are people with much bigger ones out there.



3.What is the relationship between iteration and the analysis of a large set of data?
One can generate a program to iterate a block of code that preforms an action on each datum in the set. For example, a program could examine a set of numbers and for each number that is over 10, increase a variable by 1.

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?

a is a string, b is a tuple, and 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 false statement whereas others require a number. These varibales 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 the decimal places need to be accounted for.

Thursday, December 4, 2014

Tweet
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?

41 characters. Yes becuase 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])
a is stored, and b is stored. c is stored as 'one' from a, a new part; ' and ' and b. then the print command calls c, but only characters 6 through 10; "d an"