SlideShare a Scribd company logo
Python 2
Variables, Assignment and
Types
Personality Tester
yournumber = input("Please enter a number between 1 and 99: ")
print "You entered " , yournumber
print "Performing personality analysis on your number choice …"
if yournumber < 49:
print "You are truly inadequate"
else:
print "You have delusions of grandeur"
print "That's all folks"
Values
• A basic thing – a letter or a number
• Values have TYPES
• Integers 1, 29485
• Strings “Hello world”
• Float – floating point 3.14159
Variables
• A variable has a value
mynumber
Variable names
• Can’t begin with a number
• Can’t contain spaces or other funnies
• Can’t be a keyword
– Type help() and press return
– Then type keywords in the box.
Assignment
Putting a Value ‘into’ a Variable
• myVariable = 23
• myLongVariable = “Hello how’s it going”
Sometimes written with an arrow
• myVariable 23
Assignment is really a sort of COPY
Why?
Assignment quiz
• What’s the value of myVariable
myVariable = 22
mySecondVariable = 13
myVariable = mySecondVariable
myVariable = str(myVariable)
Statements
• A statement is a piece of code that
Python can execute.
• Lots of statements make a script
• Scripts are the same as programs
Operators
• Operators ‘do things’ to operands
• The simplest operators are the math
+ addition 5+2
- subtraction 5-2
* multiplication 5*2
/ division 5/2
** exponentiation 5**2
% modulo 5%2
Now we can do the first part of the Python Challenge!
A useful program
• Write a Fahrenheit to Celsius converter
• The formula for the conversion is: F = 1.8 * C + 32
• To make this program work you will need to do the
following:
Get the user input using input(“your prompt here”)
Assign the result to a variable.
• That will give you a number, but it will be in a string type.
You’ll need to convert it to an integer type using
int(variablename).
• Now you have an integer, multiply it by 1.8 and add 32
• Print the result – your answer, to the screen with
print variablename
Challenge
• Write a script/program that allows you to
input two numbers and calculates their:
– Product
– Sum
– Difference
– Quotient (one number divided by the other
without any remainder)
– Remainder (remainder when one is divided by
the other)
– Exponent (one number to the power of the other)
Challenge 2
• Create an object
• Find its type
– Print (type(myobject))
• Find its id
– Print (id(myobject))
• What is that?

More Related Content

What's hot (20)

PPT
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Anjali Technosoft
 
PPTX
Algorithm and flowchart with pseudo code
hamza javed
 
DOCX
Oop lab assignment 01
Drjilesh
 
PPTX
Intro To C++ - Class 10 - Control Statements: Part 2
Blue Elephant Consulting
 
PPT
8.2 approach in problem solving (9 hour)
Fiqry Suryansyah
 
PPTX
Algorithms and flowcharts
Samuel Igbanogu
 
PPT
2.3 Apply the different types of algorithm to solve problem
Frankie Jones
 
PPSX
Ic lecture7
AttaullahRahimoon
 
PPTX
Flowchart and algorithm
DHANIK VIKRANT
 
PPTX
Flowcharting and Algorithm
Zeinna Belle Desamito
 
PPSX
Problem solving and design
Renée Howard-Johnson
 
PPT
Penyelesaian masalah
Unit Kediaman Luar Kampus
 
PPTX
Algorithm and flowchart
Rabin BK
 
PDF
Algorithms and how to write an algorithms
Ahmed Nobi
 
PPT
Computer programming:Know How to Flowchart
Angelo Tomboc
 
PPT
Pseudocode algorithim flowchart
fika sweety
 
PPTX
Intro To C++ - Class 09 - Control Statements: Part 1
Blue Elephant Consulting
 
PPT
Csc 130 class 2 problem analysis and flow charts(2)
Puneet narula
 
PPTX
Type Conversion, Precedence and Associativity
Aakash Singh
 
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Anjali Technosoft
 
Algorithm and flowchart with pseudo code
hamza javed
 
Oop lab assignment 01
Drjilesh
 
Intro To C++ - Class 10 - Control Statements: Part 2
Blue Elephant Consulting
 
8.2 approach in problem solving (9 hour)
Fiqry Suryansyah
 
Algorithms and flowcharts
Samuel Igbanogu
 
2.3 Apply the different types of algorithm to solve problem
Frankie Jones
 
Ic lecture7
AttaullahRahimoon
 
Flowchart and algorithm
DHANIK VIKRANT
 
Flowcharting and Algorithm
Zeinna Belle Desamito
 
Problem solving and design
Renée Howard-Johnson
 
Penyelesaian masalah
Unit Kediaman Luar Kampus
 
Algorithm and flowchart
Rabin BK
 
Algorithms and how to write an algorithms
Ahmed Nobi
 
Computer programming:Know How to Flowchart
Angelo Tomboc
 
Pseudocode algorithim flowchart
fika sweety
 
Intro To C++ - Class 09 - Control Statements: Part 1
Blue Elephant Consulting
 
Csc 130 class 2 problem analysis and flow charts(2)
Puneet narula
 
Type Conversion, Precedence and Associativity
Aakash Singh
 

Similar to Python part two names and types (20)

PPTX
Python for beginner, learn python from scratch.pptx
olieee2023
 
PDF
Python Data Types
athithanvijay
 
PDF
Python lecture no1introduction to python.pdf
QuettaLiteraryFestiv
 
PPTX
Presentation1 (1).pptx
BodapatiNagaeswari1
 
PPTX
Python.pptx
EliasPetros
 
PPTX
03 Variables - Chang.pptx
Dileep804402
 
PPTX
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
ODP
An Intro to Python in 30 minutes
Sumit Raj
 
PPTX
Python.pptx
AshaS74
 
PPTX
Review old Pygame made using python programming.pptx
ithepacer
 
PDF
The python fundamental introduction part 1
DeoDuaNaoHet
 
PPTX
Review 2Pygame made using python programming
ithepacer
 
PPTX
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
PPTX
Python Basics
Adheetha O. V
 
PPTX
lecture 2.pptx
Anonymous9etQKwW
 
PDF
Day 1 - Python Overview and Basic Programming - Python Programming Camp - One...
One Year Programming
 
PDF
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
PDF
Introduction to phyton , important topic
akpgenious67
 
PDF
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
PDF
python 34💭.pdf
AkashdeepBhattacharj1
 
Python for beginner, learn python from scratch.pptx
olieee2023
 
Python Data Types
athithanvijay
 
Python lecture no1introduction to python.pdf
QuettaLiteraryFestiv
 
Presentation1 (1).pptx
BodapatiNagaeswari1
 
Python.pptx
EliasPetros
 
03 Variables - Chang.pptx
Dileep804402
 
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
An Intro to Python in 30 minutes
Sumit Raj
 
Python.pptx
AshaS74
 
Review old Pygame made using python programming.pptx
ithepacer
 
The python fundamental introduction part 1
DeoDuaNaoHet
 
Review 2Pygame made using python programming
ithepacer
 
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Python Basics
Adheetha O. V
 
lecture 2.pptx
Anonymous9etQKwW
 
Day 1 - Python Overview and Basic Programming - Python Programming Camp - One...
One Year Programming
 
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
Introduction to phyton , important topic
akpgenious67
 
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
python 34💭.pdf
AkashdeepBhattacharj1
 
Ad

More from grahamwell (20)

PPTX
Pseudocode
grahamwell
 
PPT
Excel =if function
grahamwell
 
PPT
Excel Min max-average
grahamwell
 
PPTX
What is binary and why do we use it?
grahamwell
 
PPTX
Introduction to touch develop
grahamwell
 
PPTX
Introduction to touch develop
grahamwell
 
PPTX
The software story
grahamwell
 
PPTX
Turtle graphics
grahamwell
 
PPTX
Database field types
grahamwell
 
PPTX
Databases 101
grahamwell
 
PPTX
Kodu controls
grahamwell
 
PPTX
Abstraction - Year 9
grahamwell
 
PPTX
Thinking about your project
grahamwell
 
PPTX
The rail fence
grahamwell
 
PPT
Lesson 1
grahamwell
 
PPT
Rsa encryption
grahamwell
 
PPT
Server side scripts
grahamwell
 
PPTX
Revision topic 1 sensors and control
grahamwell
 
PPTX
Mtslesson
grahamwell
 
PPT
Hashing
grahamwell
 
Pseudocode
grahamwell
 
Excel =if function
grahamwell
 
Excel Min max-average
grahamwell
 
What is binary and why do we use it?
grahamwell
 
Introduction to touch develop
grahamwell
 
Introduction to touch develop
grahamwell
 
The software story
grahamwell
 
Turtle graphics
grahamwell
 
Database field types
grahamwell
 
Databases 101
grahamwell
 
Kodu controls
grahamwell
 
Abstraction - Year 9
grahamwell
 
Thinking about your project
grahamwell
 
The rail fence
grahamwell
 
Lesson 1
grahamwell
 
Rsa encryption
grahamwell
 
Server side scripts
grahamwell
 
Revision topic 1 sensors and control
grahamwell
 
Mtslesson
grahamwell
 
Hashing
grahamwell
 
Ad

Recently uploaded (20)

PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
July Patch Tuesday
Ivanti
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
July Patch Tuesday
Ivanti
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 

Python part two names and types

  • 2. Personality Tester yournumber = input("Please enter a number between 1 and 99: ") print "You entered " , yournumber print "Performing personality analysis on your number choice …" if yournumber < 49: print "You are truly inadequate" else: print "You have delusions of grandeur" print "That's all folks"
  • 3. Values • A basic thing – a letter or a number • Values have TYPES • Integers 1, 29485 • Strings “Hello world” • Float – floating point 3.14159
  • 4. Variables • A variable has a value mynumber
  • 5. Variable names • Can’t begin with a number • Can’t contain spaces or other funnies • Can’t be a keyword – Type help() and press return – Then type keywords in the box.
  • 6. Assignment Putting a Value ‘into’ a Variable • myVariable = 23 • myLongVariable = “Hello how’s it going” Sometimes written with an arrow • myVariable 23 Assignment is really a sort of COPY Why?
  • 7. Assignment quiz • What’s the value of myVariable myVariable = 22 mySecondVariable = 13 myVariable = mySecondVariable myVariable = str(myVariable)
  • 8. Statements • A statement is a piece of code that Python can execute. • Lots of statements make a script • Scripts are the same as programs
  • 9. Operators • Operators ‘do things’ to operands • The simplest operators are the math + addition 5+2 - subtraction 5-2 * multiplication 5*2 / division 5/2 ** exponentiation 5**2 % modulo 5%2 Now we can do the first part of the Python Challenge!
  • 10. A useful program • Write a Fahrenheit to Celsius converter • The formula for the conversion is: F = 1.8 * C + 32 • To make this program work you will need to do the following: Get the user input using input(“your prompt here”) Assign the result to a variable. • That will give you a number, but it will be in a string type. You’ll need to convert it to an integer type using int(variablename). • Now you have an integer, multiply it by 1.8 and add 32 • Print the result – your answer, to the screen with print variablename
  • 11. Challenge • Write a script/program that allows you to input two numbers and calculates their: – Product – Sum – Difference – Quotient (one number divided by the other without any remainder) – Remainder (remainder when one is divided by the other) – Exponent (one number to the power of the other)
  • 12. Challenge 2 • Create an object • Find its type – Print (type(myobject)) • Find its id – Print (id(myobject)) • What is that?