Transcript Variable

To Start
1. Create C:\100 folder
2. Create a shortcut on desktop or taskbar to Python IDLE
Values

Python has a set of recognized value types





Integer (int)
Real (float)
String (str)
Boolean (true, false)
Python has functions to switch types



int()
float()
str()
Operators

Arithmetic


+, -, *, /, ** (exponentiation), // (integer division), % (mod)
String

+ (concatenation)
Names: variables & functions

Variable
 Holds a value

Function
 We implement algorithms (recipes)
 Has parameters, arguments in ()
 Returns a value (mapping)
Naming Convention for both
Variables and Functions
• MUST start with a letter followed by alphanumeric
• aVar, cs100, …
• CASE matters
• ‘Print’ is not the same as ‘print’
• ‘makePicture’ is not the same as ‘makepicture’,
nor as ‘Makepicture’
• Multi-word name
• First letter is capitalized
• Convention, not absolute rule
• Use sensible, meaningful name
An imaginary wedding computer
def marry(husband, wife):
sayVows(husband)
sayVows(wife)
pronounce(husband, wife)
kiss(husband, wife)
def sayVows(speaker):
print “I, “ + speaker + “ blah blah”
def pronounce(man, woman):
print “I now pronounce you…”
def kiss(p1, p2):
if p1 == p2:
print “narcissism!”
if p1 <> p2:
print p1 + “ kisses “ + p2
An imaginary wedding computer
def marry(husband, wife):
sayVows(husband)
sayVows(wife)
pronounce(husband, wife)
kiss(husband, wife)
def sayVows(speaker):
print “I, “ + speaker + “ blah blah”
def pronounce(man, woman):
print “I now pronounce you…”
def kiss(p1, p2):
if p1 == p2:
print “narcissism!”
if p1 <> p2:
print p1 + “ kisses “ + p2
Lab 1
•
•
•
•
Ask what the name is
Ask what the major is
Ask what the school is
Print “My name is …. studying ... at ....”
• Email the screenshot of Python Shell (IDLE) to the
grader.