Python Boot Camp - University of California,...
Transcript of Python Boot Camp - University of California,...
Announcements
Office hours Friday 9AM - 12 PM
Please email me if you want to meet
Will find a place
New syllabus on the boot camp website
Shebang
Shebang!
#! usr/bin/env python
Tells the program loader unambiguously which interpreter to use
Sort of like the document type declaration at the top of HTML pages
Please start including this statement at the top of your Python scripts
Agenda
Review Day 4 Exercises
What we’ve learned so far
Today’s labs posted to the course website
Conditions, recursion, and loops
Day 4 ExercisesHow do you start?
for or while
no do-while in Python
while True = always execute, need your exit condition
Why couldn’t we write return eval(line) and then callprint eval_loop2()?
What happens inside the while loop?
Day 4 ExercisesBut now if the user enters ‘done’ we need to print out the value of the last expression *groan!*
Which instructions are inside the while loop? And which are outside?
Second print return_value is outside the while loop
Day 4 ExercisesThink Python 8.11
any_lowercase1 only checks if the first character in the string is lowercase
any_lowercase2 checks to see if the string ‘c’ is lowercase, which is always True
any_lowercase3 only checks the last character. The variable ‘flag’ is reset to the next character each time the loop executes
any_lowercase4 is correct!
any_lowercase5 returns False if there are any upper case letters in the string
Day 4 ExercisesThink Python Exercise 8.12
1. Start from the zero-eth index
2. Change the first letter to a numeric code,
3. add an integer,
4. Convert back to a character
Week 1 RecapFormal vs. natural languages
Python syntax
Data Types
Printing
Statements, Expressions
Variable assignment
Math operators
Functions, function definitions, function calls
Getting input from the user,
Casting (to integers, floats, strings)
Importing modules
Week 1 RecapEncapsulation
Generalization
Recursion
Conditions
Scopes and Namespaces
Boolean Logic and Operators
Iteration (Loops)
Data Validation
Try/Except
Formatted Strings
Strings
Indexing, Slicing
String Methods
Lab
Day 5 on the course website lists the labs
Go to it!
Use your neighbors for help
Let me know if you have questions