Python for Beginners Python for Beginners...1

Size: px
Start display at page:

Download "Python for Beginners Python for Beginners...1"

Transcription

1 Python for Beginners Python for Beginners...1 Lesson 0. A Short Intro... 2 Lesson 1. My First Python Program... 2 Lesson 2. Input from user... 3 Lesson 3. Variables... 3 Lesson 4. If Statements... 5 Structure... 6 How If Statements Work... 7 Lesson 5. Simple Loops... 9 Lesson 6. Data Types Integers and Floats Strings Lesson 7. Data Structures Lists Dictionaries Lesson 8. Loops For loops While loops Appendix A. Solutions... 23

2 Lesson 0. A Short Intro First, if you haven't heard of python already, you might be wondering what it means. In addition to being a snake-like animal, python is also a programming language. Python, is well-known for being an easy language to learn. Lesson 1. My First Python Program Let's start with a simple python program. Step 0. Open Python Shell by going Start (Windows logo at the bottom left) ->All Programs->Python 2.7->IDLE (Python GUI). A window should open with a white background and some black text that reads something like: Python (r252:60911, Feb , 13:11:45) [MSC v bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE >>> Step 1. Python commands can now be typed into the Python Shell. The interpreter in Python Shell will compile and run those lines of code interactively. Try typing the following command: print "Alice in Wonderland" Step 2. What happens? Alice in Wonderland should be printed to the screen. The print command just prints anything you tell it to print. Try printing your own messages to the screen. Make sure to include the quotes around your message (explanation to follow). It could be anything like: print "Oh dear! Oh dear! I shall be too late!" print "DRINK ME" print "EAT ME"

3 Lesson 2. Input from user Now your program can print all the things the white rabbit says, the bottle says, and the cookie says. How about what YOU want to tell the program? Step 0. If you haven't done so already, open a Python Shell. Step 1. Type the following line into the command line: print raw_input("enter 1 if you want to drink me, 2 if you don't: ") Step 2. What did your program say? It should have showed Enter 1 if you want to drink me, 2 if you don't: Step 3. Answer with 1 or 2. What happens? Lesson 3. Variables Now we can get the input from user, but for more fun, we want "react" to what user has said. For example, if the user said 1, then we want to shrink Alice! To do so, your program needs to remember what the user said. A computer program remembers by storing what user has said in a "variable". You've probably already learned something similar to variables. Have you taken algebra? Remember problems like 4x + 2 = 14, where you need to solve for x? x is like a variable! x has a value, it's storing the data 3 in the equation (4*3 + 2 = 14). In computer programming, we're usually more explicit in naming our variables. We can use any letters, numbers, or an underscore, to name our variables. So, instead of x, we might want to have a variable called answer or rabbit or firstname. Then we assign a value to this variable. The value can be of any data type. Let's see this in practice: Step 0. If you haven't done so already, open a Python Shell. Step 1. Type the following lines into the command line:

4 firstname = "Alice" print firstname This might not seem very interesting, but it is! The variable, firstname, is being assigned "Alice". The quotation marks around Alice means that this is a String - a text. The print command is printing the value, what's inside of the variable firstname. What can we do with this? Step 2. Let's try adding the last name to the first name. Type the following into the command line: firstname + " Lewis" What happens? 'Alice Lewis' should be printed! The single quotation marks mean that Python understands that Alice Lewis is a text. The python interpreter is using the value of "Alice" for the variable firstname and is adding " Lewis" to "Alice", which turns out to be a new text "Alice Lewis". Step 3. What if we created another variable, let's say lastname and assigned that a value. Could we then add firstname and lastname? Try these commands: lastname = "Lewis" firstname + " " + lastname You should see 'Alice Lewis' printed to the screen. Step 4. OK, now let's test the "variable" aspect of variables. The Wikipedia definition says that variables are named "variable" because the values can be changed. Try assigning a different value to firstname: firstname = "Carol" print firstname firstname is now 'Carol'. Sweet, variables really are variable. Step 5. This doesn't seem too useful yet, but let's begin a little example that will help you realize how powerful this can be. It will be called "Knock Knock Joke". Your program will play the knock knock joke with you. Your program will start by saying "Knock Knock", and then the program will ask "Who's there?". To begin our example,

5 see if you can create a variable, called name. Now can you make your program to say the name and "who?" Here's what the beginning of the code should look like: print "Knock Knock" name = raw_input("who's there? ") This assigns whatever name you typed to the variable name. You can print name to see if it has the correct name. print name Great, now we have the name you typed. Can you figure out how to print "who?" after the name? (Solution 1 in Appendix A) Before we do anything else, let's move this code to a file so we don't have to keep typing it over and over again. Open a new window by going File->New Window in Python Shell, and write the code into the file. Save the file as knockknock.py, and save it directly to My Documents. You can run the code in the file by opening it (File- >Open) and clicking on Run->Run Module. In your Python Shell, you will see the result as below: >>> ================================ RESTART ================================ >>> Knock Knock Who's there? Lesson 4. If Statements "OK, great," you might say, "I can create variables. I can do knock knock jokes. But this isn't very interesting. How does my program shrink Alice when the user says 1?" Let's take your Alice question: "What if I want to take a number and print a message based on the number?" For example, you might want to print a simple message such as "Alice shrank!" or "A white rabbit just passed!" based on the number. You could think of it this way: given the answer from the user, if the number is 1 ("Drink me"), then print "Alice shrank!". Otherwise, print "Alice grew taller!". I'll write this in another way:

6 answer = raw_input("enter 1 if you want to drink me, 2 if you don't: ") if answer == "1": print "Alice shrank!" else: print "A white rabbit just passed!" Guess what, that's python code! This is called an "if statement". There are a couple important things to know about if statements. First, you should know the general structure. Then you should know how they work. Let's just look at the structure first. Structure In the if statement above, there are 2 blocks of code. One block is under the if statement, the other block is under the else statement. Notice that the code blocks are indented. I used a tab here, but you could also use spaces. The important thing is that all lines of code in the same code block are indented the exact same amount. This leads me to my next point... In the example above, each block has only 1 line of code, but that's not always the case. There could be several lines of code in each block. Here's an example: if temperature >= 80: temperature = 80 print "Hot" else: temperature = 79 print "Cold" Like I mentioned earlier, all code in the block needs to be indented the same amount. One final thing note about the structure: you need to place a colon (:) after the if statement and the else statement. Look at the code again. if temperature >= 80: print "Hot" else: #<- colon here print "Cold" #<- colon here

7 See the colons? If you don't include these, there will be an error when you try to run your code. The colons tell python that the if and else statements are over and the next lines of code are the code blocks. Step 0. Now that you know the structure, try entering the following code into the Python Shell. temperature = 80 if temperature >= 80: print "Hot" else: print "Cold" You might notice that after you enter the if statement line, three dots appear (...). That's normal. Also, remember to indent the lines in the code blocks. Finally, hit the enter key twice after you're done typing the last line. What is the output? It should say Hot. Here's a screen shot of what it looks like: How If Statements Work The code after the word if (temperature >= 80) is called a boolean expression. Huh? Boolean expression is a really strange term. Basically, it means that the expression is either true or false. You can use the following comparison operators to form a boolean expression: ==,!=, <, <=, >=, >. Most of these are straight forward, except for maybe the == and!= comparison operators. Can you guess what == does? It checks if one piece of data is equal to another. Why not just use 1 equal sign instead of 2, you might ask? Good question. Python already uses one equal sign to mean "assignment". In other words, if you wrote temperature = 80, python would think you're assigning the value 80 to the temperature variable. A different symbol has to be used for comparison, and that's ==. Now how about!=. Can you guess what this does? It means not equal to. For example, you might want to say "if the temperature is not equal to 80, do something interesting."

8 Step 0. Here are some examples of boolean expressions, fill out their meaning (the first one is done for you as an example): name == "Alice" Meaning: name is equal to "Alice" price < 20 Meaning: grade >= 80 Meaning: temperature!= -50 Meaning: Going back to the code above, the temperature variable is first set to 80. Then, python evaluates the boolean expression temperature >= 80. In this case it's true, which means runs the code block under the if statement and skips the code under the else statement. If it was false, it would run the code block under the else statement and skip the code under the if statement. There's actually one more type of statement that you can use: the elif statement. Any idea what this might stand for? else if. This gives us even more options for our if statements. Here's an example: temperature = 78 if temperature >= 80: print "Hot" elif temperature >=70: print "Just right" elif temperature >= 60: print "A little bit cold" else: print "Cold" The elif statement is placed between the if and else statements and includes a boolean expression like the if statement. You can add as many elif statements as you want! You could even have 1000 if you wanted! During the execution of the program, the boolean expression in the if statement is first tested. If it is true, the code block under the if statement is executed and the rest is skipped. If it is false, the boolean

9 expression in the next elif statement is tested. If that boolean expression is true, the code in the code block will be executed and the rest is skipped. If none of the boolean expressions are true, only the code in the else statement is executed. Can you figure out the output of the code above? (Solution 2, Appendix A) What if the temperature was 66? (Solution 3, Appendix A) Let's try an example. Step 1. Open a Python Shell as usual. Step 2. Given the following if statement, what will happen? weather = raw_input("how's the weather today? ") if weather == "sunny": print "Play tennis" elif weather == "cloudy: print "Go shopping" elif weather == "raining": print "See a movie" else: print "Not sure what to do!" Now test it yourself in the Python Shell. Lesson 5. Simple Loops Imagine that you have to do the same thing over and over again. It would be tiring and boring, right? Computers are perfect for doing the repetition for you. Let's start with printing the same thing multiple times. Step 1. Given the following print statement, what will happen? print "*"*5 Step 2. Try the following range statement, what happens? range (1,5) Step 3. Let's print a triangle. Try with different ranges to make different triangles.

10 >>> for i in range (1,5):... print "*"*i... * ** *** **** Step 4. Can you print a triangle like this? **** *** ** * Step 5. Challenge! Can you print a triangle like this? * *** ***** ******* Lesson 6. Data Types Integers and Floats Now to explain the quotes around your message as seen above. We place quotes around the message to let python know that those characters are a string. This is not the kind of string your cat plays with; it's a data type. OK, but what's a data type? The Wiktionary definition for data type is "a classification or category of various types of data, that states the possible values that can be taken,... and what range of operations are allowed on them". 1 In other words, a data type gives meaning to a piece of data in a computer program. If I asked you what 1 is, you would probably say it's a number, correct? Saying that 1 is a number is similar to giving data in a computer program a type. Number is the data type of 1. Let's see how this applies to the Wiktionary definition: 1.

11 "states the possible values that can be taken" - what are the possible values of a number? answer: negative infinity to infinity "what range of operations are allowed on them" - what operations can be performed on numbers? answer: addition, subtraction, division, multiplication, etc. Python has a couple numerical data type; one is called Integer. Integers can be added, subtracted, divided, multiplied, etc. Let's take a look at this in the Python Shell. Step 0. If you haven't already, open a Python Shell. Step 1. Enter the following command and press enter: type(1) What happens? <type 'int'> is displayed. This is telling you that 1 is of the type 'int'. 'int' is short for integer. Pretty cool! Step 2. Now try adding 2 integers. Type this and press enter: 1+3 You should see 4 appear on the line below. Now try some other operations. You can subtract (-), divide (/), and multiply (*). Here are some examples: /2 78* /4*5 3/2 Integer isn't the only numerical data type; another is called float. Floats are very similar to integers. The main difference is that they include a decimal point, which allows for more precision. Floats can be added, subtracted, divided, and multiplied just like integers. Step 3. Try these in the Python Shell:

12 * /2 If you're wondering why some of the answers might not be exactly right (they might look like this: ), this is because the decimal point numbers are stored as approximations. Please see the python documentation for a more thorough explanation ( Strings Strings are another data type. Can you figure out what Strings are? They are basically any text. Like in the message you printed in Lesson 1, strings are surrounded by quotes. Python is pretty relaxed about the type of quotes, you can use either double quotes (") or single quotes ('). I'll use them both in the exercises from now on. Let's try playing with strings in the Python Shell! Step 0. What does python say is the type of "hello"? Use type() again to see what the type of "hello" is: type("hello") What does it say? 'str', short for string. Step 1. Enter a print statement again to print a message. It can be something like this: print "hello again!" Step 2. Can arithmetic operations be performed on strings, too? Can they be added, multiplied, subtracted, or divided? Try the following operations and see what happens: "this" + "that" "this" - "that" "this" * "that" "this" / "that" The first one works just fine. It outputs the string "thisthat". Makes sense, right? You might want to create a larger string from smaller strings in your computer program.

13 For example, you might want to add "Hello, " plus a person's name if you wanted to greet a user to your website. The other operations fail with an error message. This also makes sense. Could you even imagine how "this" - "that" would work?? Step 3. Let's try to be a little sneaky, and see what happens when we enter the following commands (make sure to include the quotes!): "2" + "5" "4" - "7" "12" * "56" "18" / "4" The same outcome as above! Only the first one works, giving the output "25". The others fail. So, even though these are numbers, python interprets them as strings because of the quotes. Step 4. We can be even sneakier and change the type of those strings to an integer. How to do this, you ask? Simply, convert them to an integer by using the int() method (more about methods later.. don't worry about this word yet). Try this at the command line: int("2") * int("4") What happens? 8 should be printed! Sweet. Data can be changed from one type to another. Step 5. Let's try the reverse, converting an integer to a string. Type this into the Python Shell: str(5) + str(7) Can you guess what will be printed? OK, moving on to data structures...

14 Lesson 7. Data Structures Lists Data structures allow a programmer to group together sets of data in a logical manner. Python has a few data structures; the 2 that we'll go over are lists and dictionaries. First, lists. How do you use lists in your own life? Personally, I use lists to keep track of the groceries I need to buy at the store or the tasks I need to do during the day. Lists could be related to TV: for example, there is a list of the channels that you get on your cable or what shows are going to on at 8pm on Tues. We use lists very often in real life; it makes sense to use them in computer programming, too! In the Facebook code, a list might be used to store all your friends. Or the code on your TiVo might use a list to save a list of all the TV shows on PBS. Can you think of how other applications might use a list? In python, a list is represented by square brackets ([]). Let's try creating a new list: Step 0. Open a Python Shell as usual. Step 1. At the command line, type the following: tvshows = [] Great! We now have a variable, tvshows, that is a list data type. (You can verify this by using type(tvshows).) But our TV show list is empty right now, which isn't very useful. Let's add some TV shows to our list. Step 2. To add data to our list, you need to use the append method of the list class. OK, what? What's a method? What's a class? Both methods and classes are a way to modularize code, making the code better organized and reusable. Methods are a way of grouping code together to perform a single action. For example, you might create a method to take 2 numbers and return the sum of the numbers. The append method adds data to the end of a list. If you think of a method as a way of grouping code together to perform a single action, then you can think of a class as a way of grouping methods and variables together to perform many actions that are all related in some way. Classes in programming can sometimes relate to real world objects. The classic example is a

15 bank account (a little boring, yes, but it's easy to visualize). In your bank account class, you would have a variable for the total amount of money in the account. Then you could add methods such as deposit(money) or withdraw(money) that add or subtract money from the total amount. If you're interested in learning more about methods and classes, I strongly encourage you to read the python documentation (methods, aka functions - controlflow.html#defining-functions and classes - classes.html). Back to our lists! We wanted to add data to our tvshows list. To do so, enter the following code into the command line: tvshows.append("curiosity Quest") This adds "Curiosity Quest" to our list. How can we be sure? Step 3. Print the list to make sure the data was really added: print tvshows Yup, Curiosity Quest was added to the list. Try adding some more TV shows to the list! Step 4. Like many things you'll find in programming, there is often more than one way to accomplish a task. We could create a new list and add the values in one step. Try typing the following lines into the Python Shell to see what happens: moretvshows = ["Arthur", "Angelina Ballerina", "WordGirl"] print moretvshows Step 5. There are some cool things you can do with lists. For one, you can print the length. To do so, use the len method to get the length of the list: len(tvshows) Step 6. You can also access single items in the list. Let's say you wanted to access just the 1st element to change it's value: tvshows[0] = "Martha Speaks"

16 You might be saying: wait, that's a zero, not 1! Why is zero used to access the first element instead of 1? In computer programming, someone decided a long time ago to start counting at 0 rather than 1. So, the "index" of our list starts with 0, 1, 2... To access the second element, use 1 as the index: tvshows[1] = "High School Musical" What happens if you use a really, really large index that is definitely bigger than our list? Give it a try: tvshows[100000] An error! Step 7. Python has a really cool feature that allows you easy access to the last element in the list. You can use -1 as the index. Example: tvshows[-1] What happens when you type this? It should display the last item in your list! It might not seem very useful now, but trust me, I've used it several times in some complex programs! Step 8. Lastly, you can sort lists. This can be extremely useful. Try this code in the Python Shell: numbers = [4, 3, 5, 1, 2] numbers.sort() print numbers The numbers in the list are now sorted! This will also work on lists of strings, putting the strings in alphabetical order. Dictionaries OK, those are the basics of lists. Now let's go over dictionaries. Like lists, we often use dictionaries in real life. A good example: the dictionary. :) Think about the dictionary for a second. What is it doing? It's actually acting like a python dictionary on 2 levels. First, it groups all the words that start with a certain letter into different sections. If I said to you, give me all the words that start with A, you would open the dictionary, turn to the page that A starts on, and start reading the words. Not only does it do

17 this, but it also maps a word to its definition(s). If I asked you for the definition of the word "tangerine", you would be able to look up tangerine and give me the definition. What's common in these 2 functions? I ask for something by giving you a letter or a word (ie, a key), and you give me back something that relates to that key (ie, a value for that key). The dictionary is mapping keys to values. Can you think of anything else in real life that acts like a dictionary? I can think of a couple: an encyclopedia or a phone book. Since we use dictionaries in real life, it makes sense to have them in computer programming, too (like lists!). Going back to Facebook, Facebook might want to use a dictionary to map a person's name to their friends. Netflix might use a dictionary to map a user to their queue of movies. The contact list on your cell phone might map your friends' names to their phone number. Let's see how this works in python. In python, the dictionary is represented as curly brackets ({}). Let's create a dictionary mapping names to phone numbers: Step 0. Create a new dictionary: phone_book = {} And that's it! We have our new dictionary. Let's add some names and phone numbers to our phone book. Step 1. Add a name that maps to the person's phone number: phone_book['bob'] = ' ' Does this notation look somewhat familiar? Maybe similar to the lists we learned about earlier? That's cuz it's identical. Yea. One less thing to remember! Lists are just dictionaries with integers as keys. Step 2. Now that we have Bob in our address book, let's say you want to get his phone number. You can do so like this: print phone_book['bob'] Or, you might have noticed that Bob is just a string, and strings can be saved in variables, so we could even do something like this: name = "Bob"

18 print phone_book[name] Step 3. Add some more people and phone numbers to the phone_book dictionary. When done, use the command print phone_book to verify the names and phone numbers have been added properly. Step 4. Now let's change Bob's phone number. How do you think you would do this? Try it yourself, the solution is in Appendix A (Solution 4). Step 5. Similar to lists, dictionaries can be created in one step: phone_book2 = { "Bob":" ", "Susan":" ", "Kelly":" " } Note the syntax: { key:value, key:value... } Step 6. There are some cool things you can do with dictionaries. For example, you can get a list of all the keys. Try this: phone_book.keys() Or you can get a list of all the values. Try this: phone_book.values() Step 7. What if you wanted to combine lists and dictionaries?? So far, we've only been using strings as the values, but the values can be integers, dictionaries, floats, even other dictionaries! Going back to our TV example, what if we wanted to map a list of tv shows to a channel? For example, we could map the channel PBS to a list of shows on PBS. See if you can figure the code out on your own first. (Some shows on PBS are "Arthur", "Angelina Ballerina" and "Sid the Science Kid". If you need help, one possible answer is in Appendix A (Solution 5)!

19 Lesson 8. Loops For loops Remember the other problem we wanted to solve earlier: what if we wanted to loop through every item in a list and perform some operation on the value? For example, let's say we had a list of names, maybe all your friends on Facebook, and we wanted to print out all their names. You could say it like this: for each friend in my friend list, print the person's name. I'll write it one more way: friends = ['Stephanie', 'Amy', 'Candice', 'Maggie'] for name in friends: print name Guess what! That's python code! This is called a for loop. The for loop loops through each item in the list and allows you to perform some operation on that item. In this example, our operation is to print the item. Look at the structure of this code. Similar to our if statements, there's a code block that's indented. Although this example has only one line of code in the block, there can be more than one line. Each line has to be indented the same amount. Also notice that there's another colon at the end, just like the if statements! Here's a more complex example. Let's say we wanted to create a website that found the best deals on clothes by "scraping" other sites for pricing information. For example, we might scrape macys.com and nordstrom.com for the price of a pair of Guess jeans. We would first save the links in a list. We could then open a connection to each link and get the contents of the page. We could have a certain pattern we might want to match on the page, maybe something like $number.number, and save any content that matches that pattern for later use. Here's what the code might look like (don't worry if you don't understand it all, just notice that it uses a for loop!): urls = [" " product/425", " for url in urls: page_contents = open(url).read() matches = re.search("(\$\d+\.\d{2})", page_contents) match = Match(url=url, matches=matches) match.save() Let's try some examples!

20 Step 0. Open the Python Shell. Step 1. Enter the following code and hit Enter twice: for i in range(5): print i What happens when you run the code? This should be printed: Step 2. Why does the previous code print 0 to 4? To answer that question, try typing this into the Python Shell: print range(5) What is printed? [0, 1, 2, 3, 4]. What does that look like? If you guessed a list, you would be correct! The range method is creating a list of integers from 0 to 4. The list starts at 0, then ends at the number before 5. If you tried range(10), can you guess what list would be created? Step 3. Let's try another example. Type this code into the Python Shell to see what it does: phone_numbers = { "Anna":" ", "James":" ", "Mike":" " } for name in phone_numbers.keys(): print phone_numbers[name] Remember that the keys() method retrieves a list of all the keys in the dictionary. The loop then loops through all the keys and uses the key to print associated phone number. Step 4. Your turn! Write code to do the following: for each number in the range 0 to 9, print the result of that number times itself. (See Appendix A, Solution 6 for one possible solution)

21 While loops There's another type of loop available in python: while loops. The basic idea behind a while loop is that the loop keeps running the code block while something is true and stops once it become false. For example, you might want to build a music player that keeps playing music while the user has not pressed the stop button. Once the user presses the stop button, the program stops playing the music. Here's a simple example of a while loop: counter = 1 while counter < 10: print counter counter = counter + 1 What does this code do? It keeps printing the counter value until the counter is no longer less than 10. While loops have a boolean expression, just like if statements. In this example, why does the counter value increase? Because you keep adding 1 every time you loop (line 4). What would happen if you didn't add one to the counter or did something like this: counter = 1 while counter < 10: print counter counter = 1 This will run forever! We call this an infinite loop. Sometimes you might want to use an infinite loop, but most often you don't. :) An infinite loop could also be written like this: while True: print 'hi' Time to practice. Step 0. Open the Python Shell if you haven't done so already. Step 1. Try this code for yourself: counter = 1 while counter < 10:

22 print counter counter = counter + 1 Does it work like you expected? Step 2. Now try an infinite loop. To stop the program, you'll have to hit CTRL-C. while True: print 'hi' Step 3. Write a while loop that prints the numbers 0 to 4 then stops. (See Appendix A, Solution 7 for one possible solution) Remember you did something like this with a for loop? Often what can be accomplished with a for loop can also be accomplished with a while loop! Step 4. Let's finish up the Gift Card Example we were working on earlier. Here's the code you should have so far in your giftcard.py file (if it's not the same, take a moment to change it to match): gift_card_value = 20 cost = 12 sales_tax_rate =.095 tax = cost * sales_tax_rate total_cost = tax + cost print total_cost left_over = gift_card_value - total_cost if left_over < 0: print "Over budget" else: print "OK" print left_over Let's make some really cool changes. First, we'll get input from the user rather than 'hard-coding' the gift card value and item cost. To get input from the user, you can use the input method. It looks sometime like this: gift_card_value = int(raw_input('enter the amount of your gift card: ')) cost = int(raw_input('enter the amount of the item: '))

23 Try adding these lines to the program, replacing the first 2 lines. Run the program to see what happens. Step 5. How about we let the user input the cost of several items instead of just one? We can let them keep entering the cost of items until they enter the character 'q'. Sounds like we might want to use a loop to solve this problem, huh? We would want cost to represent the entire cost of all the items, adding each item's cost to this value as the user enters it. Once the user enters 'q', the program would stop asking for input from the user and then continue with the rest of the calculations. Here are the steps: get the gift card value set the cost variable to zero get the item_cost from the user (Hint: item_cost = raw_input("enter a cost: ")) while the item_cost is not equal to 'q' add the item_cost to the cost (Hint: cost = cost + int(item_cost)) get the item_cost from the user again...continue with the rest of the program Try to translate these steps to python code. (See Appendix A, Solution 8 for one possible solution) Appendix A. Solutions Solution 1. print name+" who?" Solution 2. Just right Solution 3. A little bit cold Solution 4. phone_book['name'] = ' '

24 or phone_book['bob'] = ' ' Solution 5. gift_card_value = 20 cost = 12 sales_tax_rate =.095 tax = cost * sales_tax_rate total_cost = tax + cost print total_cost left_over = gift_card_value - total_cost if left_over < 0: print "Over budget" else: print "OK" print left_over Solution 6. for i in range(10): print i*i Solution 7. counter = 0 while counter < 5: print counter counter = counter + 1 Solution 8. gift_card_value = int(raw_input('enter the amount of your gift card: ')) item_cost = raw_input('enter the amount of the item (Enter q to stop): ') cost = 0 while item_cost!= 'q': cost = cost + int(item_cost) item_cost = raw_input('enter the amount of the item (Enter q to stop): ') sales_tax_rate =.095

25 tax = cost * sales_tax_rate total_cost = tax + cost print total_cost left_over = gift_card_value - total_cost if left_over < 0: print "Over budget" else: print "OK" print left_over

MITOCW watch?v=se4p7ivcune

MITOCW watch?v=se4p7ivcune MITOCW watch?v=se4p7ivcune The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

MITOCW watch?v=0jljzrnhwoi

MITOCW watch?v=0jljzrnhwoi MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

MITOCW watch?v=flgjisf3l78

MITOCW watch?v=flgjisf3l78 MITOCW watch?v=flgjisf3l78 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To

More information

Skill 1: Multiplying Polynomials

Skill 1: Multiplying Polynomials CS103 Spring 2018 Mathematical Prerequisites Although CS103 is primarily a math class, this course does not require any higher math as a prerequisite. The most advanced level of mathematics you'll need

More information

MITOCW watch?v=rvrkt-jxvko

MITOCW watch?v=rvrkt-jxvko MITOCW watch?v=rvrkt-jxvko The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

BEGINNER PHP Table of Contents

BEGINNER PHP Table of Contents Table of Contents 4 5 6 7 8 9 0 Introduction Getting Setup Your first PHP webpage Working with text Talking to the user Comparison & If statements If & Else Cleaning up the game Remembering values Finishing

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Lecture 2 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To make a donation

More information

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto CS 170 Java Programming 1 The Switch Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Menu-Style Code With ladder-style if-else else-if, you might sometimes find yourself writing menu-style

More information

MITOCW ocw f99-lec07_300k

MITOCW ocw f99-lec07_300k MITOCW ocw-18.06-f99-lec07_300k OK, here's linear algebra lecture seven. I've been talking about vector spaces and specially the null space of a matrix and the column space of a matrix. What's in those

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Recitation 1 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

Post Experiment Interview Questions

Post Experiment Interview Questions Post Experiment Interview Questions Questions about the Maximum Problem 1. What is this problem statement asking? 2. What is meant by positive integers? 3. What does it mean by the user entering valid

More information

MITOCW watch?v=9h6muyzjms0

MITOCW watch?v=9h6muyzjms0 MITOCW watch?v=9h6muyzjms0 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

Lesson 4: Who Goes There?

Lesson 4: Who Goes There? Lesson 4: Who Goes There? In this lesson we will write a program that asks for your name and a password, and prints a secret message if you give the right password. While doing this we will learn: 1. What

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Chapter 4 Lab. Loops and Files. Objectives. Introduction

Chapter 4 Lab. Loops and Files. Objectives. Introduction Chapter 4 Lab Loops and Files Objectives Be able to convert an algorithm using control structures into Java Be able to write a while loop Be able to write a do-while loop Be able to write a for loop Be

More information

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this

More information

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1 Pupil Name Year Teacher Target Level Spelling Test No 1 Spelling Test No 2 Spelling Test No 3 1) 2) 3) 4) 5) 1) 2) 3) 4) 5) 1) 2) 3) 4) 5) Spelling Test No 4 Spelling Test No 5 Spelling Test No 6 1) 2)

More information

Starting. Read: Chapter 1, Appendix B from textbook.

Starting. Read: Chapter 1, Appendix B from textbook. Read: Chapter 1, Appendix B from textbook. Starting There are two ways to run your Python program using the interpreter 1 : from the command line or by using IDLE (which also comes with a text editor;

More information

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below. Name: Date: Instructions: PYTHON - INTRODUCTORY TASKS Open Idle (the program we will be using to write our Python codes). We can use the following code in Python to work out numeracy calculations. Try

More information

the rules The Goal Get all three of your monkeys around the board and into the Banana Grove before anyone else can!

the rules The Goal Get all three of your monkeys around the board and into the Banana Grove before anyone else can! the rules Equipment Code Monkey Island Gameboard, 12 monkey figurines (three of each color), 54 Guide cards, 16 Fruit cards, 10 Boost in a Bottle cards. The Goal Get all three of your monkeys around the

More information

Python for Non-programmers

Python for Non-programmers Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013

More information

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. Guide to and Hi everybody! In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. This guide focuses on two of those symbols: and. These symbols represent concepts

More information

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5 Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5 [talking head] This lecture we study theory design and implementation. Programmers have two roles to play here. In one role, they

More information

MITOCW watch?v=w_-sx4vr53m

MITOCW watch?v=w_-sx4vr53m MITOCW watch?v=w_-sx4vr53m The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To

More information

MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON

MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON Table of contents 2 1. Learning Outcomes 2. Introduction 3. The first program: hello world! 4. The second program: hello (your name)! 5. More data types 6.

More information

The Big Python Guide

The Big Python Guide The Big Python Guide Big Python Guide - Page 1 Contents Input, Output and Variables........ 3 Selection (if...then)......... 4 Iteration (for loops)......... 5 Iteration (while loops)........ 6 String

More information

IDM 232. Scripting for Interactive Digital Media II. IDM 232: Scripting for IDM II 1

IDM 232. Scripting for Interactive Digital Media II. IDM 232: Scripting for IDM II 1 IDM 232 Scripting for Interactive Digital Media II IDM 232: Scripting for IDM II 1 PHP HTML-embedded scripting language IDM 232: Scripting for IDM II 2 Before we dive into code, it's important to understand

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

MITOCW watch?v=4dj1oguwtem

MITOCW watch?v=4dj1oguwtem MITOCW watch?v=4dj1oguwtem PROFESSOR: So it's time to examine uncountable sets. And that's what we're going to do in this segment. So Cantor's question was, are all sets the same size? And he gives a definitive

More information

CS 190C: Introduction to Computational Thinking

CS 190C: Introduction to Computational Thinking CS 190C: Introduction to Computational Thinking http://secant.cs.purdue.edu/cs190c:start Python Programming: An Introduction to Computer Science Zelle s book is a gentle introductory computing text used

More information

Part III Appendices 165

Part III Appendices 165 Part III Appendices 165 Appendix A Technical Instructions Learning Outcomes This material will help you learn how to use the software you need to do your work in this course. You won t be tested on it.

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block THE IF STATEMENT The if statement is used to check a condition: if the condition is true, we run a block of statements (called the if-block), elsewe process another block of statements (called the else-block).

More information

MITOCW ocw f99-lec12_300k

MITOCW ocw f99-lec12_300k MITOCW ocw-18.06-f99-lec12_300k This is lecture twelve. OK. We've reached twelve lectures. And this one is more than the others about applications of linear algebra. And I'll confess. When I'm giving you

More information

Expressions and Variables

Expressions and Variables Expressions and Variables Expressions print(expression) An expression is evaluated to give a value. For example: 2 + 9-6 Evaluates to: 5 Data Types Integers 1, 2, 3, 42, 100, -5 Floating points 2.5, 7.0,

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

C++ Reference NYU Digital Electronics Lab Fall 2016

C++ Reference NYU Digital Electronics Lab Fall 2016 C++ Reference NYU Digital Electronics Lab Fall 2016 Updated on August 24, 2016 This document outlines important information about the C++ programming language as it relates to NYU s Digital Electronics

More information

CS Summer 2013

CS Summer 2013 CS 1110 - Summer 2013 intro to programming -- how to think like a robot :) we use the Python* language (www.python.org) programming environments (many choices): Eclipse (free from www.eclipse.org), or

More information

Decisions, Decisions. Testing, testing C H A P T E R 7

Decisions, Decisions. Testing, testing C H A P T E R 7 C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little

More information

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. Plan for the rest of the semester: Programming We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. We saw earlier that computers

More information

Types, lists & functions

Types, lists & functions Week 2 Types, lists & functions Data types If you want to write a program that allows the user to input something, you can use the command input: name = input (" What is your name? ") print (" Hello "+

More information

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

C# Programming Tutorial Lesson 1: Introduction to Programming

C# Programming Tutorial Lesson 1: Introduction to Programming C# Programming Tutorial Lesson 1: Introduction to Programming About this tutorial This tutorial will teach you the basics of programming and the basics of the C# programming language. If you are an absolute

More information

Regular Expressions Explained

Regular Expressions Explained Found at: http://publish.ez.no/article/articleprint/11/ Regular Expressions Explained Author: Jan Borsodi Publishing date: 30.10.2000 18:02 This article will give you an introduction to the world of regular

More information

CONDITION CONTROLLED LOOPS. Introduction to Programming - Python

CONDITION CONTROLLED LOOPS. Introduction to Programming - Python CONDITION CONTROLLED LOOPS Introduction to Programming - Python Generating Random Numbers Generating a random integer Sometimes you need your program to generate information that isn t available when you

More information

Math Day 2 Programming: How to make computers do math for you

Math Day 2 Programming: How to make computers do math for you Math Day 2 Programming: How to make computers do math for you Matt Coles February 10, 2015 1 Intro to Python (15min) Python is an example of a programming language. There are many programming languages.

More information

Lists, loops and decisions

Lists, loops and decisions Caltech/LEAD Summer 2012 Computer Science Lecture 4: July 11, 2012 Lists, loops and decisions Lists Today Looping with the for statement Making decisions with the if statement Lists A list is a sequence

More information

Problem Solving for Intro to Computer Science

Problem Solving for Intro to Computer Science Problem Solving for Intro to Computer Science The purpose of this document is to review some principles for problem solving that are relevant to Intro to Computer Science course. Introduction: A Sample

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

MITOCW watch?v=yarwp7tntl4

MITOCW watch?v=yarwp7tntl4 MITOCW watch?v=yarwp7tntl4 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality, educational resources for free.

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

(Python) Chapter 3: Repetition

(Python) Chapter 3: Repetition (Python) Chapter 3: Repetition 3.1 while loop Motivation Using our current set of tools, repeating a simple statement many times is tedious. The only item we can currently repeat easily is printing the

More information

How Do Robots Find Their Way?

How Do Robots Find Their Way? How Do Robots Find Their Way? Conditionals and Repetition http://en.wikipedia.org/wiki/file:cyclope_robot.jpg http://www.youtube.com/watch?v=_l9rklaskwu Learning Objectives Learn basic programming concepts

More information

Maxime Defauw. Learning Swift

Maxime Defauw. Learning Swift Maxime Defauw Learning Swift SAMPLE CHAPTERS 1 Introduction Begin at the beginning, the King said, very gravely, and go on till you come to the end: then stop. Lewis Carroll, Alice in Wonderland Hi and

More information

Variables and Constants

Variables and Constants 87 Chapter 5 Variables and Constants 5.1 Storing Information in the Computer 5.2 Declaring Variables 5.3 Inputting Character Strings 5.4 Mistakes in Programs 5.5 Inputting Numbers 5.6 Inputting Real Numbers

More information

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can

More information

Out for Shopping-Understanding Linear Data Structures English

Out for Shopping-Understanding Linear Data Structures English Out for Shopping-Understanding Linear Data Structures English [MUSIC PLAYING] [MUSIC PLAYING] TANZEELA ALI: Hi, it's Tanzeela Ali. I'm a software engineer, and also a teacher at Superior University, which

More information

MITOCW watch?v=ytpjdnlu9ug

MITOCW watch?v=ytpjdnlu9ug MITOCW watch?v=ytpjdnlu9ug The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality, educational resources for free.

More information

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT LESSON VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT PROF. JOHN P. BAUGH PROFJPBAUGH@GMAIL.COM PROFJPBAUGH.COM CONTENTS INTRODUCTION... Assumptions.... Variables and Data Types..... Numeric Data Types:

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Recitation 4 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To make

More information

MIT AITI Python Software Development

MIT AITI Python Software Development MIT AITI Python Software Development PYTHON L02: In this lab we practice all that we have learned on variables (lack of types), naming conventions, numeric types and coercion, strings, booleans, operator

More information

Program Planning, Data Comparisons, Strings

Program Planning, Data Comparisons, Strings Program Planning, Data Comparisons, Strings Program Planning Data Comparisons Strings Reading for this class: Dawson, Chapter 3 (p. 80 to end) and 4 Program Planning When you write your first programs,

More information

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2 Python for Analytics Python Fundamentals RSI Chapters 1 and 2 Learning Objectives Theory: You should be able to explain... General programming terms like source code, interpreter, compiler, object code,

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

More information

GENERAL MATH FOR PASSING

GENERAL MATH FOR PASSING GENERAL MATH FOR PASSING Your math and problem solving skills will be a key element in achieving a passing score on your exam. It will be necessary to brush up on your math and problem solving skills.

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently. The Science of Computing I Lesson 4: Introduction to Data Structures Living with Cyber Pillar: Data Structures The need for data structures The algorithms we design to solve problems rarely do so without

More information

INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0

INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0 INTERMEDIATE LEVEL PYTHON PROGRAMMING SELECTION AND CONDITIONALS V1.0 OCTOBER 2014 Python Selection and Conditionals 1 SELECTION AND CONDITIONALS WHAT YOU MIGHT KNOW ALREADY You will probably be familiar

More information

Condition Controlled Loops. Introduction to Programming - Python

Condition Controlled Loops. Introduction to Programming - Python + Condition Controlled Loops Introduction to Programming - Python + Repetition Structures n Programmers commonly find that they need to write code that performs the same task over and over again + Example:

More information

Module 6. Campaign Layering

Module 6.  Campaign Layering Module 6 Email Campaign Layering Slide 1 Hello everyone, it is Andy Mackow and in today s training, I am going to teach you a deeper level of writing your email campaign. I and I am calling this Email

More information

Memory Addressing, Binary, and Hexadecimal Review

Memory Addressing, Binary, and Hexadecimal Review C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend

More information

Python Intro GIS Week 1. Jake K. Carr

Python Intro GIS Week 1. Jake K. Carr GIS 5222 Week 1 Why Python It s simple and easy to learn It s free - open source! It s cross platform IT S expandable!! Why Python: Example Consider having to convert 1,000 shapefiles into feature classes

More information

Most of the class will focus on if/else statements and the logical statements ("conditionals") that are used to build them. Then I'll go over a few

Most of the class will focus on if/else statements and the logical statements (conditionals) that are used to build them. Then I'll go over a few With notes! 1 Most of the class will focus on if/else statements and the logical statements ("conditionals") that are used to build them. Then I'll go over a few useful functions (some built into standard

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

The Stack, Free Store, and Global Namespace

The Stack, Free Store, and Global Namespace Pointers This tutorial is my attempt at clarifying pointers for anyone still confused about them. Pointers are notoriously hard to grasp, so I thought I'd take a shot at explaining them. The more information

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation, and we wrote a rather stylized

PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation, and we wrote a rather stylized MITOCW Lecture 4A PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation, and we wrote a rather stylized program to implement a pile of calculus rule from the calculus book. Here on the

More information

Introduction to programming with Python

Introduction to programming with Python Introduction to programming with Python Ing. Lelio Campanile 1/61 Main Goal - Introduce you to programming - introduce you to the most essential feature of python programming 2/61 Before to start The name

More information

Python: common syntax

Python: common syntax Lab 09 Python! Python Intro Main Differences from C++: True and False are capitals Python floors (always down) with int division (matters with negatives): -3 / 2 = -2 No variable data types or variable

More information

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

Programming Fundamentals and Python

Programming Fundamentals and Python Chapter 2 Programming Fundamentals and Python This chapter provides a non-technical overview of Python and will cover the basic programming knowledge needed for the rest of the chapters in Part 1. It contains

More information

Welcome to Python 3. Some history

Welcome to Python 3. Some history Python 3 Welcome to Python 3 Some history Python was created in the late 1980s by Guido van Rossum In December 1989 is when it was implemented Python 3 was released in December of 2008 It is not backward

More information

QUICK EXCEL TUTORIAL. The Very Basics

QUICK EXCEL TUTORIAL. The Very Basics QUICK EXCEL TUTORIAL The Very Basics You Are Here. Titles & Column Headers Merging Cells Text Alignment When we work on spread sheets we often need to have a title and/or header clearly visible. Merge

More information

Arduino IDE Friday, 26 October 2018

Arduino IDE Friday, 26 October 2018 Arduino IDE Friday, 26 October 2018 12:38 PM Looking Under The Hood Of The Arduino IDE FIND THE ARDUINO IDE DOWNLOAD First, jump on the internet with your favorite browser, and navigate to www.arduino.cc.

More information

MITOCW watch?v=kz7jjltq9r4

MITOCW watch?v=kz7jjltq9r4 MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection

More information

Python 1: Intro! Max Dougherty Andrew Schmitt

Python 1: Intro! Max Dougherty Andrew Schmitt Python 1: Intro! Max Dougherty Andrew Schmitt Computational Thinking Two factors of programming: The conceptual solution to a problem. Solution syntax in a programming language BJC tries to isolate and

More information

Instructor: Craig Duckett. Lecture 03: Tuesday, April 3, 2018 SQL Sorting, Aggregates and Joining Tables

Instructor: Craig Duckett. Lecture 03: Tuesday, April 3, 2018 SQL Sorting, Aggregates and Joining Tables Instructor: Craig Duckett Lecture 03: Tuesday, April 3, 2018 SQL Sorting, Aggregates and Joining Tables 1 Assignment 1 is due LECTURE 5, Tuesday, April 10 th, 2018 in StudentTracker by MIDNIGHT MID-TERM

More information

Control, Quick Overview. Selection. Selection 7/6/2017. Chapter 2. Control

Control, Quick Overview. Selection. Selection 7/6/2017. Chapter 2. Control Chapter 2 Control, Quick Overview Control Selection Selection Selection is how programs make choices, and it is the process of making choices that provides a lot of the power of computing 1 Python if statement

More information

Unit 9 Tech savvy? Tech support. 1 I have no idea why... Lesson A. A Unscramble the questions. Do you know which battery I should buy?

Unit 9 Tech savvy? Tech support. 1 I have no idea why... Lesson A. A Unscramble the questions. Do you know which battery I should buy? Unit 9 Tech savvy? Lesson A Tech support 1 I have no idea why... A Unscramble the questions. 1. which battery / Do you know / should / buy / I? Do you know which battery I should buy? 2. they / where /

More information

Intro. Classes & Inheritance

Intro. Classes & Inheritance Intro Functions are useful, but they're not always intuitive. Today we're going to learn about a different way of programming, where instead of functions we will deal primarily with objects. This school

More information

Making ecards Can Be Fun!

Making ecards Can Be Fun! Making ecards Can Be Fun! A Macromedia Flash Tutorial By Mike Travis For ETEC 664 University of Hawaii Graduate Program in Educational Technology April 4, 2005 The Goal The goal of this project is to create

More information

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto Side Effects The 5 numeric operators don't modify their operands Consider this example: int sum = num1 + num2; num1 and num2 are unchanged after this The variable sum is changed This change is called a

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information