introduction to python n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Python PowerPoint Presentation
Download Presentation
Introduction to Python

Loading in 2 Seconds...

play fullscreen
1 / 15

Introduction to Python - PowerPoint PPT Presentation


  • 82 Views
  • Uploaded on

Introduction to Python. Lesson 2a Print and Types. Learning Outcomes. In this lesson the students will: Print a message that contains text, numbers and calculations Create variables with proper names Perform calculations using addition, subtraction and multiplication.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction to Python' - crwys


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introduction to python

Introduction to Python

Lesson 2a

Print and Types

learning outcomes
Learning Outcomes
  • In this lesson the students will:
  • Print a message that contains text, numbers and calculations
  • Create variables with proper names
  • Perform calculations using addition, subtraction and multiplication
more on printing print
More on printing: print()
  • print() can print text in quotes, numbers and calculations separated by commas
  • For example:

print(“1+2 = ”, 1+2)

1+2 = 3

variables and values
Variables and values
  • A variable is a named piece of memory that stores a value
  • To create a variable in Python:
    • write the name of the variable and assign it a value num_1 = 10

= means assignment (store the value on the right in the variable on the left)

example
Example
  • So what if I wanted to create another variable to store the value 7 and print it to the screen?
  • Let’s do it in IDLE together
sample code
Sample code

num_1=7

print(num_1)# Easy print example

print(“The value is ”, num_1) # better example

naming variables
Naming variables
  • Must begin with a letter (a - z, A - Z) or underscore (_)
  • Remaining characters can be letters, numbers or _
  • Case Sensitive
  • Can be any (reasonable) length
  • Can’t be a keyword
  • The following is recommended:
    • Always start a variable name with a lowercase letter.
    • Use underscores to separate words.
    • Use meaningful names
valid names
Valid names
  • My_var
  • my_var
  • $_123
  • number!
  • thisIsAVARiableDoYOuLikeIT
  • print
kinds of values
Kinds of values
  • Python allows us to store different types of values (data types or classes). For example:
  • Integers: whole numbers e.g. 5, 899, 12
  • Strings: A stringis a sequence of one or more characters.
    • Strings start and end with quote " or apostrophe ' characters.

name = "Hello"str1= "This is a string"str2 ="This is a really reallyreally long string!"

example1
Example
  • Write a program that creates two Strings. The first String should store your first name and the second string should store your surname. Print your full name to the screen on a single line.
  • Write a program that has two integer variables, one with the value 100 and the other with the value 15. Print out the values in the variables.
sample code1
Sample Code

first_name = “John”

surname=“Doe”

print(first_name, surname)

____________________________________________

num_1 = 100

num_2 = 15

print(num_1, num_2)# better with a message

example2
Example
  • Write a program that creates two integer variables, gives them values and then prints the sum of the variables to the screen.
sample code2
Sample Code

num_1 = 10

num_2 = 20

print(num_1,“+”, num_2, “=”, num_1+num_2)

lesson review
Lesson Review
  • In this lesson …