Thursday, December 11, 2014

1.3.8 Guesser Thing






  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 would need 6000 guesses, because you could guess 1 then 2 then 3, and if the correct number was 6000, you'd need 6000 guesses. I guess. 
  1. Describe the difference between a while loop and a for loop.

While will continue until a certain variable changes, and it can be affected mid-way through its run-time. A for loop will run a specific amount of time, and you can't change the amount of times it is run. 



Tuesday, December 9, 2014

1.3.7 Options


This was the code for the Lottery option. You had to input your ticket numbers, and it created the winning numbers. It gave you an output of the number of similar numbers.


This is the code for Hangman. Running hangman() will initiate it. It stops after the word is guessed. I stored the words as lists, not strings. So ['w','o','r','d'] not "word."


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.

This would make the code very long and repetitive, and would make it very difficult to change the iteration. 

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

A list of words, like names or words in a text document, or if you were searching for a word in that document. You would want to iterate through it, it would be nearly impossible without iteration.

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

To analyze a large set of data, you'd need to iterate through it to read each piece of data.



Friday, December 5, 2014

1.3.6 Guess a Letter


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 string is just a word, letter, or sentence. A list/tuple can be the same thing but it's all divided into individual strings. Tuples are a fixed size, while lists are much more dynamic. You can't add or remove elements of a tuple, but you can with a list.
2.  Why do computer programming languages almost always have a variety of variable types? 
 They have a variety of types so that they can be more efficient under different circumstances. For example Boolean logic is very useful if you just need True or False, and not complicated numbers or sentences. Having integers and strings make math easier to do, especially if you want 5 to be '5' and not a number.
3.  Why can't everything be represented with an integer?
Because some things aren't integers? Floats aren't integers and neither are strings. Integers can be used in math, but it would fail if you tried to use integers as strings. 

Wednesday, December 3, 2014

1.3.5 Check Tweet Post





The comments are in the screenshot.

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?

The total characters is each letter, space, and symbol used in the sentence. Python would need to store it as 1 byte so that the length of "hi" isn't 8.

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.

c would be "one" + " and " + "another", so it would be "one and another".
it would print 6-10 of c, so "d an".

It will remeber each letter's variable, and then combine parts (bytes) from each variable.