Lecture 2 Review CodeCademy 1a Run my CodeCademy and review the assignments Floats or integers The difference is left implicit Try Float1 isinstance 22 float Float2 isinstance ID: 434337
Download Presentation The PPT/PDF document "Python:" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Python:
Lecture 2Slide2
Review
CodeCademy 1a
Run my
CodeCademy
and review the assignments.Slide3
Floats or integers
The difference is left implicit. Try:
Float1 =
isinstance
( 2.2, float)
Float2 =
isinstance
( 2., float)
Float3 =
isinstance
( 22, float)
Print Float1, Float2, Float3.
Conclusion
?Slide4
Division is briefly touched
Try:
X1 = 22/3
X2 = 22./3.
X3 = 22./3
X4 = 22/3.
Print X1, X2, X3, X4
Conclusion ?Slide5
The modulo operator
The example is strange:
3 % 2 = 1
How unrevealing is this:
Both the integer division
and
the remainder after division are 1 !!!! So which one is it??
Try:
X = 5 % 2
Print XSlide6
When does a variable get introduced ?
Consider:
X = meal
m
eal = 1
Print X
Conclusion ?
Note: there will be other ways to introduce a variable (e.g. as argument to a function definition)Slide7
Tip calculator
Trivial?Slide8
STRings
& Console output
Review assignmentsSlide9
Date and Time
Review it. No special comments.
Importing code will be important at later stages.Slide10Slide11
More exercises from LPTHWSlide12
Assignment for the next week
CodeCademy
3a: Conditionals and control flow (30 min.)
CodeCademy
3b:
PygLatin
(11 min)
From LPTHW: Ex.27 (2 min),
you do not need to memorize this !!
Ex.28 (35 min –
includes debugging –view ex!)
Careful: True == not(True and False) gives syntax error !! You need:
True == (not(True and False))
Ex.29 (6 min), Ex.30 (6 min)