I'm trying to challenge myself and learn new skills and ways of thinking. I've always wanted to learn to code. Someone gave me a Python Book. So I'm starting there.
Don't wanna be here? Send us removal request.
Text
It’s been a hot second
I got off track and wasn’t as persistent. I’m reexamining how I’m doing this. I’m not sure what it will turn into.
I’m really happy I’ve been taking a Coursera class. It kept me on track. I was also happy I financially invested into it. Now it’s getting interesting!
3 notes
·
View notes
Text
Chapter 2 Notes - Think Python
Chapter 2 Variables, expressions and Statements One of the most powerful features of a programming language is the ability to manipulate variables. A variable is a name that refers to a value 2.1 Assignment statements An assignment statement creates a new variable and gives it value. Example: >>>message='And now for something completely different >>>n=17 >>>pi=3.14 This example makes three assignments. The first assigns a string to a new variable named message. The second statement gives the integer 17 to n. The third assigns a value to pi. A state diagram is a written way of representing variables. it shows the name with an arrow pointing to its value.
2.2 Variable names Programmers generally choose names for their variables that are meaningful. Variable names: Can be as long as you like can contain both letters and number can use uppercase letters (but normally do noy) can use underscore character (_) your_name airspeed_of_unladen_swallow Things that will make a variable name illegal starting a name with a number >>>76trombones='big parade' SyntaxError: invalid syntax Using an illegal character >>>more@=10000 SyntaxError: invalid syntax Using a keyword >>>class='Advanced Theoretical Zymurgy' SyntaxError: invalid syntax The interpreter uses keywords to recognize the structure of the program. They cannot be used as variable names There are 33 keywords for Python. It is not necessary to memorize the list. Keywords are often displayed in a different color. If you try to use one as a variable name, you'll know. 2.3 Operators and operands Operators: special symbols that represent computations like addition and multiplication. Operands: the values the operator is applied to In Python 2, the division operator works differently than how you'd expect. >>>minute=59 >>>minute/60 0 This reason for the discrepancy is because Python is performing floor division. When both operands are integers, the result is also an integer Floor division rounds down to the nearest integer (0) In Python 3, the result of the same division is a float. If either of the operands is a floating-point number, Python performs floating-point division, and the result is a float >>> minute/60.0 0.98333 2.4 Expressions and Statements Expression: a combination of values, variables and operators. A value alone can be an expression A variable alone can be an expression Statement: A unit of code that the Python interpreter can execute So far we have seen two kinds of statements: print assignment Technically and expression is also a statement. The important difference is that an expression has a value; a statement does not. 2.5 Interactive mode and script mode When you work with the interactive mode, you can test bits of code before putting them into a script. If using Python as a calculator: In Interactive mode: >>>miles=26.2 >>>miles*1.61 42.18 The first line assigns a value to miles. But has no visible effect. The second line is an expression, so the interpreter evaluates it and displays the result. In script mode: miles=26.2 print miles*1.61 You get no output at all. In script mode, an expression, all by itself, has no visible effect. Python actually evaluates the expression, but it doesn't display the value unless you tell it to. A script usually contains a sequence of statements. If there is more than one statement, the results appear one at a time as the statements execute. For example the script print 1 x=2 print x Produces the output 1 2 The assignment statement produces no output 2.7 Order of operations Rules of Precedence determine the order of evaluation. Python follows the same rules of precedence as in math. The acronym PEMDAS helps to remember this. Parentheses Exponentiation Multiplication and Division Addition and Subtraction Operators with the same precedence are evaluated from left to right
2.8 String operations In general, you can't perform mathematical operations on strings, even if the strings look like numbers. So, the following are illegal: '2'-'1' 'eggs'/'easy' 'third'*'a charm' The operator works with strings in an unexpected way. It performs concatenation: which means joining the strings by linking them end-to-end. For example: first='throat' second='warbler' print first+second The output of this program is throatwarbler The * operator also works on strings, but it performs repetition For example: 'spam'*3 is 'spamspamspam' If one of the operands is a string, the other has to be an integer
2.9 Comments Because of how dense programs are,it is wise to add note4s to programs to explain in natural language what the program is doing. These are called comments and they start with the # sign percentage=(minute*100) #percentage of an hour Everything from the # to the end of the line is ignored-it has no effect on the execution of the program Comments are most useful when they document non-obvious features of the code It is reasonable to assume the reader can figure out what the code does; it is more useful to explain why This comment with the code is redundant and useless: v=5 #assign 5 to v This comment contains useful information that is not in the code v=5 # velocity in meters/second Good variable names can reduce the need for comments, but long names can make complex expressions hard to read, so there is a tradeoff
2.8 Debugging Three kinds of errors can occur in a program Syntax errors: "Syntax" refers to the structure of a program and the rules about that structure. Parentheses have to come in matching pairs. If one is missing, there is a syntax error If there is a syntax error anywhere in your program, Python displays an error message and quits. You will not be able to run the program. Runtime errors: Called "runtime" errors because the error does not appear until after the program has started running. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened These errors are rare in simple programs Semantic error "Semantic" referring to meaning. If there is a semantic error in your program, it will run without getting error messages, but it will not do the right thing. It will do something else Identifying semantic errors can be tricky because it requires you to work backward by looking at the output of the program and trying to figure out what it is doing
2.9 Glossary variable: a name that refers to a value assignment: a statement that assigns a value to a variable state diagram: a graphical representation of a set of variables and the values they refer to keyword: a reserved word that is used to parse a program; you cannot use keywords like if, def and while as variable names operand: one of the values on which an operator operates expression: a combination of variables, operators and values that represents a single result evaluate: to simplify an expression by performing the operations in order to yield a single value statement: a section of code that represents a command or action. So far, the statements we have seen are assignments and print statements execute: to run a statement and do what it says interactive mode: a way of using the Python interpreter by typing code at the prompt script mode: a way of using the Python interpreter to read code from a script and run it script: a program stored in a file order of operations: rules governing the order in which expressions involving multiple operators and operands are evaluated concatenate: to join two operands end-to-end comment: information in a program that is meant for other programmers (or anyone reading the source code) and has no effect on the execution of the program syntax error: an error in a program that makes it impossible to parse (and therefore impossible to interpret) exception: an error that is detected while the program is running semantics: the meaning of a program semantic error: an error in a program that makes it do something other than what the programmer intended
2.10 Exercises 2.1 We've seen that n=42 is legal. What about 42=n? There is a syntax error. It says it "can't assign to literal" This is because it started with a number How about x=y=1? This is legal, and same for y=x=1, it is only illegal if you start with 1 In some languages, every statement ends with a sem-colon ; What happens if you put a semi-colon at the end of a Python statement? In a math statement, it completes it. In a print statement, it give you a Syntax Error, stating "EOL while scanning string literal" What if you put a period at the end of a statement? In a math statement, it gives you a floating-point number In a print statement, it is a syntax error, saying "invalid syntax" In math notation, you can multiply x and y like this: xy. What happens if you try that in Python? It gives you a Name Error, saying xy is not defined Exercises 2.2 The volume of a sphere with radius r is 4/3pir^3. What is the volume a sphere with radius 5? >>> r=5 >>> r^3 6 >>> r**3 125 >>> 4/3*3.14159*r**3 523.5983333333332 >>> Suppose the cover price of a book is $24.95, but book stores get a 40% discount. Shipping costs $3 for the fist copy and $.75 for each additional copy. What is the total wholesale cost for 60 copies? bookCost = 24.95 numBooks = 60.0
def cost(numBooks): bulkBookCost = ((bookCost * 0.60) * numBooks) shippingCost = (3.0 + (0.75 * (numBooks - 1))) totalCost = bulkBookCost + shippingCost print 'The total cost is: $', totalCost
cost(numBooks) If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at easy pace again, what time do I get home for breakfast start_time_hr = 6 + 52 / 60.0 easy_pace_hr = (8 + 15 / 60.0 ) / 60.0 tempo_pace_hr = (7 + 12 / 60.0) / 60.0 running_time_hr = 2 * easy_pace_hr + 3 * tempo_pace_hr breakfast_hr = start_time_hr + running_time_hr breakfast_min = (breakfast_hr-int(breakfast_hr))*60 breakfast_sec= (breakfast_min-int(breakfast_min))*60
print ('breakfast_hr', int(breakfast_hr) ) print ('breakfast_min', int (breakfast_min) ) print ('breakfast_sec', int (breakfast_sec) ) >>>
I still need to figure out how to take my notes and keep their formatting when I paste on to here. That will come someday, but for now, let’s keep learning!
2 notes
·
View notes
Text
Opportunities to learn-- YESS!
Just found this contest through Women Tech Makers to enter to win a free tech course from Udacity! OF COURSE I SIGNED UP!
https://www.womentechmakers.com/udacity
0 notes
Text
Long way to go, and not mad about it
I was doing the exercises in my Think Python book. I checked them, and man was I when I tried it. I’ve got a long way to go and definitely need to practice. I really did not realize there was an expectation to define each variable. I think I was expecting to do too much calculation in my head
I love that there is so much content out there on learning to code! I want to find more exercises so that way I can work on improving!
0 notes
Text
I caved!
I’m really curious about getting fundamentals down. I caved, and I paid for a Coursera class. I still plan on using my note taking. I just want the Coursera class to reinforce everything properly!
0 notes
Text
CodeNewbie Podcast
I’ve been trying to find any and every resource to help me immerse myself in the coding world. I found the CodeNewbie podcast which seems to focus on Ruby. While I’m trying to learn Python, I still think it’s awesome! It really so far has focused on developers who started out a little later in life.
http://www.codenewbie.org
I’m hoping I can find an equivalent to Python. But for now, I’m just loving the concept! It’s very inspiring and I’ve been trying to listen to it every day on my commute.
0 notes
Text
Another resource!
I really want to immerse myself into this as much as possible. So even while I was cooking today, I thought I would try to continue my learning by watching videos. Admittedly this was nothing more than background noise, but I thought it would be useful to pick up some jargon, and reinforce some ideas.
Anyway, I was trying to find a video that would be helpful, and I found this series.
https://www.youtube.com/playlist?list=PL0-84-yl1fUnRuXGFe_F7qSH1LEnn9LkW
While I didn’t invest too much time into looking for ones, I thought this was the best one of the ones that I did find.
2 notes
·
View notes
Text
New Resource: WikiBooks!
For now, I’m not going to post my answers to the exercises from the Think Python book. It’s not a shame thing, so much as a time thing. I found answers to the book though on WikiBooks! YAY! https://en.wikibooks.org/wiki/Think_Python/Answers#Exercise_1.4
This is fantastic because I’m going to go crazy trying to figure out if I’m doing things right!
I really want to find even more exercises, but only so much time in a day!
0 notes
Text
Chapter 1 Notes- Think Python
Chapter 1 The way of the Program Aim is to think like a computer scientist. This includes some of the best features of mathematics, engineering, and natural science. Like in math, computer scientists use formal languages to denote ideas (specifically computations) Like engineers, they (computer scientists) design things, assembling components into systems and evaluating tradeoffs among alternatives Like scientists, they observe the behavior of complex systems, form hypotheses, and test predictions The most important skill for a computer scientist is problem solving. Problem solving: ability to formulate problems think creatively about solutions express a solution clearly and accurately
1.1 What is a program? A program is a sequence of instructions that specifies how to perform a computation The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, or it could be a symbolic computation such as searching and replacing text in a document or something graphical, like processing an image or playing a video. The details look different in different languages, but a few basic instructions appear in just about every language: Input: get data from the keyboard, a file, the network, or some other device output: display data on the screen, save it in a file, send it over the network, etc. math: Perform basic mathematical operations liked addition and multiplication Conditional Execution: check for certain conditions and run the appropriate code repetition: Perform some action repeatedly, usually with some variation Most programs are made up of instructions just like those (input, output, math, conditional execution, repetition) You can think of programing as the process of breaking a large, complex task into smaller and smaller subtasks until the subtasks are simple enough to be performed with one of the basic instructions (input, output, math, conditional execution, repetition)
1.2 Running Python A challenge with getting started with Python is that you have to install Python and related software on your computer. To do so, you'd need to be familiar with your operating system and the command-line interface For beginners, it can be painful to learn about system administration and programming at the same time To begin, use PythonAnywhere, in a browser There 2 versions of Python. They are very similar. Python 2 Python 3 The Python Interpreter: a program that reads and executes Python code. When it starts, you should see output like this: Python 3.4.0 (default, Jun 19 2015, 14:20:21) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> The first three lines contain information about the interpreter and operating system it's running on (it's likely to vary per user). You should check that the version number, which is in that example "3.4.0," begins with 3, which indicates that you're using Python 3. If you saw something like "2.4.0," the 2 would indicate that you're using Python 2 The last line is a prompt that indicates that the interpreter is ready for you to ender code. If you type a line of code and hit Enter, the interpreter displays the result: >>> 1+1 2 1.3 The first program Usually the first program you write in a new language is called, "Hello, World!" because all it does is display the words "Hello, World!" In Python, it looks like this: >>> print ('Hello, World!') This is an example of a print statement It doesn't actually print anything on paper. It displays a result on the screen. In this case, the result is the words Hello, World! The quotation marks in the program mark the beginning and end of the text to be displayed The parentheses indicate that print is a function. Functions will be discussed in Chapter 3. In Python 2, the print statement is slightly different, it is not a function, so it doesn't use parentheses. >>> print 'Hello, World!' 1.4 Arithmetic operators After "Hello, World", the next step is arithmetic. Python provides operators the special symbols that represent computations like addition and multiplication. The operators, +, -, and * perform addition, subtractions and multiplication as in the following examples: >>> 40+2 42 >>>43-1 42 >>>6*7 42 >>>84/2 42.0 The operator ** performs exponentiation; That is, it raises a number to a power: >>>6**2 42 Other languages use ^ for exponentiation, but Python in Python, ^ is a bitwise operator called XOR. Bitwise operators will not be covered in this book, but to learn more, you can read about them at: https://wiki.python.org/moin/BitwiseOperators
1.5 Values and Types A value is one of the basic things a program works with, like a letter or a number There are different types of values 2 is an integer 42.0 is a floating-point number 'Hello, World!' is a string so called because the letters it contains are strung together The interpreter can tell you what type a value has >>> type(2) <class 'int'> >>> type (42.0) <class 'float'> >>> type ('Hello, World!') <class 'str'> In these results, the word "class" is used in the sense of a category; a type is a is a category of values integers belong to the type int, strings belong to str, and floating-point numbers belong to float What about values like '2' and '42.0'? They look like numbers, but they are in quotation marks like strings. >>> type('2') <class 'str'> >>> type ('42.0') <class 'str'> They're strings. When you type a large integer, you may be tempted to use commas between groups of digits, as in 1,000,000. This is not a legal integer in Python. But it is legal: >>>1,000,000 (1, 0, 0) Python interprets 1,000,000 as a comma-separated sequence of integers.
1.6 Formal and natural languages Natural languages are the languages people speak such as English, Spanish, Chinese Natural languages were not designed by people, they evolved naturally Formal languages are languages that are designed by people for specific applications mathematicians use a formal language that is good for denoting relationships among numbers and symbols. chemists use a formal language that helps to represent the chemical structure of molecules programming languages are formal languages that have been designed to express computations Formal languages tend to have strict syntax rules Syntax rules govern the structure of statements For math, 3+3=6 correct syntax 3+=3$6 does not have correct syntax There are two flavors of syntax rules- pertaining tokens and structure tokens are the basic elements of the language, such as words, numbers and chemical elements. One of the problems with 3+=3$6 is that $ is not a legal token in mathematics structure is how the tokens are combined 3+=3 illegal because even though each token is legal, you can't have one right after the other When you read a language (natural or formal) you have to figure out (sometimes subconsciously) the structure This process is called parsing Differences between formal and natural languages ambiguity: Natural languages are very ambiguous. Formal languages are designed to be unambiguous. Any statement has exactly one meaning, regardless of context redundancy: to make up for ambiguity, and reduce misunderstandings, natural languages employ a lot of redundancy. As a result of being unambiguous, formal languages are less redundant and more concise. literalness: natural languages are full of idiom and metaphor. Formal languages mean exactly what they say. The difference between formal and natural languages is like the difference between poetry and prose, but more so: poetry: words are used for their sound as well for their meaning, and the whole poem together creates an effect or emotional response. Ambiguity is not only common, but often deliberate prose: the literal meaning of words is more important, and the structure contributes more meaning. Prose is more amenable to analysis than poetry but still often ambiguous. programs: the meaning of a computer program is unambiguous and literal, and can be understood entirely by analysis of the tokens and structure. Formal languages are more dense than natural languages. Also, the structure is very important in formal languages it isn't always best to read from top to bottom, left to right. learn to parse the program in your head, identifying the tokens and interpreting the structure details matter small errors in spelling and punctuation make a big difference in formal language. 1.7 Debugging Programming errors are called bugs The process of tracking down bugs is called debugging 1.8 Glossary Problem solving: the process of formulating a problem, finding a solution, and expressing it High-level language: a programming language like Python that is designed to be easy for humans to read and write Low-level language: a programming language that is designed to be easy for a computer to run; also called "machine language" or "assembly language" Portability: a property of a program that can run on more than one kind of computer Interpreter: a program that reads another program and executes it Prompt: Characters displayed by the interpreter to indicate that it is ready to take input from the user Program: a set of instructions that specifies a computation Print Statement: an instruction that causes the Python interpreter to display a value on the screen Operator: a special symbol that represents a simple computation like addition, multiplication, or string concatenation Value: one of the basic units of data, like a number or string that a program manipulates Type: a category of values. The types we have seen so far are integers (type int), floating-point numbers (type float) and strings (type str) Integer: a type that represents whole numbers Floating-point: a type that represents numbers with fractional parts String: A type that represents sequences of characters Natural language: Any one of the languages that people speak that evolved naturally Formal Language: Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are formal languages Token: One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language Syntax: The rules that govern the structure of a program Parse: To examine a program and analyze the syntactic structure Bug: An error in a program Debugging: The process of finding and correcting bugs
So I’m bummed this took out all of my formatting. I’ll have to look into seeing if there’s a better way of posting!
0 notes
Text
Where to begin....
A friend of mine who is a senior developer sat down with me and spent some time telling me about all of the different routes I could take in terms of learning to code. He gave me a book on coding in Python. He gave me a few different reasons why it was a good place to start. Below are his multiple bullet points as to why he steered me in that direction
1. It’s not as verbose as Java
2. It’s incredibly easy to setup your development environment and start writing code. (This is important for people who have no prior knowledge of programming languages.
3. In his experience, statically typed languages like Java are frustrating for beginners. But you’ll learn how awesome they are down the road. Python is a dynamically typed language so it’s easier for smaller projects.
4.There’s a huge huge huge community out there for leaning Python
5. Python abstracts away and hides A LOT of complicated computer science concepts from the programmer. So you don’t need (at first) understand what’s the difference between a LinkedList and ArrayList. Python picks the right one for you. Later on, it’s absolutely essential to understand what’s going on under the hood though.
Another friend of mine who is a developer did warn me to move on quickly after learning it, as there are some bad habits you can pick up. In fact, that list essentially what my friend gave to me by way of text when he heard that my other friend was challenging his choice.
I don’t want to get too distracted by where to begin, so I’m diving in.
All of that aside, the book is Think Python by Allen Downey. Below’s the link.
http://greenteapress.com/wp/think-python-2e/
0 notes
Text
Hello, World!
I’m creating this as a way to organize what I’ve learned as I begin learning about coding. I think it will become a tool to also track the different resources that assist while learning about coding.
I suppose I should start off with why I’m learning something new. The primary reason is that I miss challenging myself academically-- especially using skills like mathematics, science, problem solving, language and science. I recently wrapped up college and am in a sales job. I have a business degree, but I’m not sure if that was the best fit for me. So, I’m hoping to eventually have a career change, but that is not the primary goal.
I’m sure this blog will take many different shapes, but for now, I plan it to use it as a way for me to log my progress, track the resources I’ve found, engage with this community more and organize the things I’ve learned.
0 notes