Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Getting Input in Python Assumes assignment statement, typecasts.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
16-May-15 Sudden Python Drinking from the Fire Hose.
Python November 14, Unit 7. Python Hello world, in class.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Introduction to Python
Basic Input/Output and Variables Ethan Cerami New York
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
An Introduction to Textual Programming
Introduction to Python
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Documentation and Comments. What’s a comment? A comment is a simple form of documentation. Documentation is text that you the programmer write to explain.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Variables and Expressions CMSC 201 Chang (rev )
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
ICAPRG301A Week 2 Strings and things Charles Babbage Developed the design for the first computer which he called a difference engine, though.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
My Python Programmes NAME:.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
The Basics Input / Output, and Primitive Data Types.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add
Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CRE Programming Club Class 2 (Import JJZ543 and Practice Your Typing!)
GCSE Computing: Programming GCSE Programming Remembering Python.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
Getting Started With Python Brendan Routledge
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
JavaScript: Conditionals contd.
CMSC201 Computer Science I for Majors Lecture 03 – Variables
Lesson 03: Variables and Types
what is computer programming?
Whatcha doin'? Aims: To start using Python. To understand loops.
CMSC201 Computer Science I for Majors Lecture 02 – Intro to Python
Content Programming Overview The JVM A brief look at Structure
Data Types and Conversions, Input from the Keyboard
Variables, Expressions, and IO
Engineering Innovation Center
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
An Introduction to Python
Teaching London Computing
Introduction to TouchDevelop
Lesson 03: Variables and Types
Inputs and Variables Programming Guides.
Beginning Python Programming
Input and Output Python3 Beginner #3.
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Python Simple file reading
Programming for Business Computing Introduction
Getting Started in Python
Presentation transcript:

Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)

- 2 - Objectives We will be reviewing what we learned last week Strings / What can you do with them Variables And user Input Questions & Answers

- 3 - Follow Up We set up Python We went over strings and variables –You define a string with the quotations “I AM A STRING –You can add strings together i.e. (“test“ + “mest” = “testmest”) –You can store values in things called variables –You can add variables together

- 4 - Strings A ‘string' is simply a list of characters in order. A character is anything you can type on the keyboard in one keystroke, like a letter, a number, or a backslash. For example, “Hello, my name is Jeff!” all of the letters like H, e, l, l, 0, … are ‘strung” together to form a string. Ok how can I write a “String” and use it in python?

- 5 - Defining/Writing a String There are 3 ways of defining/writing a string, –1. ‘I am a string‘ –2. “I am a string” –3. “””I am a string””” These practically mean the same thing, but later we’ll discus the differences and how we’ll use them. Everything inside of the quotations is the string, the quotations wont be interpreted as a string.

- 6 - Using Strings First try typing hello into the command line and see what the out put is. If all goes to plan you’ll get an error. That is because hello is not defined in python as anything so the only thing python knows what to do with it is to just throw out an error, Now try typing ‘hello’ with the quotation thingies in front of and behind the word your trying to type out. You’ll get a response from python telling you that it understood what was trying to be done and it prints out ‘hello’ with no issues.

- 7 - String Examples Try to predict the out put of each string when we type them in –“test” –‘Hello, World!’ –“I am 4 years old” –‘I Like to cause errors” –“4” –‘2 + 2’

- 8 - Printing Out In python there is a built in function called print(). Print() is the command that allows you to display text on to the command line. The Print() command is called a function, and I’ll be getting into later what a function is, and we’ll get to writing out own functions just like the print() function; In this lecture I won’t be explaining how it works, I’ll just show you how to use it.

- 9 - Print() Use Ok so how to we use a print(), first of all you could just type print() in the command line, and it will do something. Lets say you want to do more. The print() function allows for data to be put in side of it, like a String, or an Int, or a Float. All of these work –print(‘I am a string’) –print(12) –print( ) All of those work

Printing Examples Try and guess the out puts of each print function –print(“Hello, World!”) –print(123) –print(“I am 4 Years Old”) –print(“2 + 2”) –print(2 + 2)

Variables What are variables? Are they the same thing as a variable in math? Yes they are, kind of, but better. You can use them to store values and use them later. Open your command prompt / terminal. Then type x = 10. you can then type x again and the number 10 will spit out. This is the most basic example / use for a variable.

Variable Names You don’t have to name your variables X, you can name them however you like. –For example type var = 123, You have just created another variable. –You can print out the number 123 by typing out var. There is also one other thing where your other variables aren’t effected. –Type X again and you’ll get the value for X back. You can do this as many times as you like. You can name your variables almost anything, you can’t have numbers in the beginning of your variable name, and there are some key words where you can’t name your variables. Keep in mind that variable names are case sensitive. –Here are some examples var = 10 Var1 = 11 x = 1 X = 2

Variable uses Variables have a specific way to set a value to them. –First you type the name of your variable –Then you use the equal sign. (The equal sign in Python means to assign a value NOT COMPARATIVE) –Then you put the value at the end of your equal sign Try to create you own variables. To get back the value just type the name of your variable and Python will give back the value. You can overwrite existing variables but just assigning a new value to it. –Type x and it should give back a value –Now assign X a new value by typing X = -12 –If you print out X it will print out -12. When you overwrite a variable in Python the last value will be lost in cyberspace.

How else can I use a Variable Variables can store more than just numbers they can store STRINGS also. –Type var = “STRING” and then print it out –You can see that var has just stored a string, you can over write this variable with a number as such var = 10 You can also store an answer of an arithmetic problem –Type var = and then print it out. –You can also type var2 = “test1” + “test2” and print it out.

How else can I use a Variable 2 Variables because variables can store values they can also do other things that you can normally do with numbers/strings –You can add variables together, make a variable called x and set it as 15, then make a variable called y and set it as 10, you can now type x + y and get back a number –You can also try making two new variables and store string values in them then add them together. –Also try creating 2 variables like x and y and add them and set them equal to a new variable like newVar = x + y

Why use variable? It makes sense to think that there is no point in making a variable when you can just type the number in your code and have it mean the same thing. You would be right in that case. What variable are used for is when you (as a programmer) don’t know what the value of the variable is going to be. This doesn’t make sense right now because you haven't used anything like that.

User Input This is an example of not knowing what the value of the number will be when writing the program. For example lets say I want to make a calculator program that asks the user for two numbers and then adds them together. As a programmer you have no idea what the numbers are going to be. All you can do is make two variable and then add them together and display the total.

User Input Usage In Python there is a built in function (similar to the print function) called input(). This input function tells the program to wait for the user to type something and displays the value of what they just typed –For example type input() in the command prompt / terminal and watch python wait for you. You can type what ever you want in their. Once you press enter Python will display what you had just typed. –You can also type in a string inside of the brackets like input(“Enter Your Number: ”). All this does is it displays that string before it waits for the user input, it is the same as the print function. Type typing input(“Enter Value: ”) and then enter a value. Try to guess what the output is going to be.

Lets try writing an input program in IDLE The Goal with this program is to prompt the user to enter his first name and last name and have python print it out.

Questions & Answers

© 2014 Chris Trenkov