Monday, December 15, 2014

Activity 1.3.8 While Loops


  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 6000 guesses to be guaranteed that you have the right answer because there are 6000 integers in the range from 1-6000. Thus, you need one guess for each integer.
  1. Describe the difference between a while loop and a for loop.
The for statement iterates through a collection of values, whereas the while statement loops through until a condition is False.

Friday, December 12, 2014

Activity 1.3.7 For Loops


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.

The disadvantages of repeating the iterated lines of code multiple times is the fact that the coder loses both time and efficiency. Also if an error were to occur somewhere in the program, it would be more difficult to find the erroneous line of code because there would be so many more to choose from as opposed to using loops.

Name a large collection across which you might iterate.

One example of a large collection across which one might iterate is a collection of books. In this, the program would have the list of all of the books, and would function with iterations to search for one specific book based on the input that the user has entered.

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

Iteration is used in the analysis of a large set of data in the fact that it goes through the list of data to find a specific key, element, line, or whatever is needed in that particular code. Thus, iteration is a very helpful and beneficial method in analyzing a large set of data. If there was no iteration, searching a list of integers for one specific integer would be time consuming, so luckily iteration is around to ease the coding and lessen the time of work for the programmers.

Friday, December 5, 2014

Activity 1.3.6 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? 
All tuples and lists are made up of strings, so they are longer and more complex. Also, tuples are immutable while lists are mutable.
2.  Why do computer programming languages almost always have a variety of variable types?    
Computer programming languages have a variety of variable types so that they can operate in an efficient manner appropriate to the scenario at hand. For example, Boolean is used for occasions where True and False are the only possible outputs.
3.  Why can't everything be represented with an integer?
Everything can't be represented with an integer because there aren't enough integers to represent everything such as letters. If all we used was integers, everybody would probably have a seizure.

Wednesday, December 3, 2014

Twitter Checker



  • Line 1 is defining the function "check_twitter"
  • Line 2 sets "message" equal to the user's input after they are prompted with "Enter Tweet here:"
  • Line 3-4 say that if the message is longer than 140 characters, the console will return with the message "Sorry, your tweet is longer than 140 characters; please try again."
  • Line 5-6 say that if either a comma, an exclamation point, or a question mark are missing from the user's tweet, the console will return with the message "Sorry, you seem to be missing either: , ! or ? Please try again." This will only occur once the tweet is less than 140 characters.
  • Lines 7-8 say that if the tweet meets all of the guidelines, the console will return with the message "Great, thanks for tweeting!"
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?
It depends on which language the code is to be written in; some languages such as English use one byte per character, while Unicode uses four bytes per character.

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])

This code creates a string "c" that adds the first 3 characters of string "a" to "and", and to the entire string "b". Thus string "c" would be "one and another".
The code would print "d an".