200 likes | 331 Views
UW CSE 140 Section. 1/09, Winter 2014. About me about you. Now it’s time to team up!. Find partners! Group can be 2-4 people. Try to share as much as possible about what you think with your teammates!. During Section.
E N D
UW CSE 140 Section 1/09, Winter 2014
Now it’s time to team up! • Find partners! Group can be 2-4 people. • Try to share as much as possible about what you think with your teammates!
During Section • Create an empty text file and save everything about what you try and what you get. • You can also include your name and your teammate’s name in the file. • Email this text file to TA after class if you still feel doubt about any part of the section.
Command Lines Intro • Command Prompt in Windows • Terminal in Mac/Linux
Command Line Basics • Show current directory/folder • pwd (on unix, linux, osx) • echo %cd% (on windows) • List contents in the current directory/folder • ls (on unix, linux, osx) • dir (mostly only on windows) • / on unix, linux, osx • \ on windows
Change directory • cd Use “tab” to loop through path! • Make directory • mkdir(on unix, linux, osx) • md (on windows)
Python with command line • Using interpreter • Using script • python myprogram.py • python myprogram.py argument1argument2 • The operating system command shell/prompt is notthe same as the Python interpreter
Exercise: Print a table • Create a table using print about the simpleinfo of your team. • The required variable fields are: First name, Last name, Month of birth in number, and Favorite color. • Your code should start with: first_name = “Michael” last_name = “Ernst” ... • Example output: ”Michael Ernst, 1, likes green""Dun-Yu Hsiao, 5, likes red"
Exercise: Print a table • Careful about the conversion between number and string • Use str(some number)
Exercise: Convert speed • Testing your program • Making a speed conversion chart mph->kph • Chart the conversion: 10, 30, 40, 60, 75, 100mph • Print out example: 10mph 16.09kph ... (Tedious, isn’t it?)
Loops: basics • Use loop to reduce code repetition! • For loop: for iterating_var in sequence: statements(s) for x in [ 10, 2, 43]: print( x )
s = 0 for x in [ 10, 2, 43]: s = s + x Equivalent to: s = 0 x = 10 s = s + x x = 2 s = s + x x = 43 s = s + x
s = 0 for x in [ 5, 6 ]: for yin [ 7, 8 ]: s = s + x + y Equivalent to: s = 0 x = 5 for y in [ 7, 8 ]: s = s + x + y x = 6 for y in [ 7, 8 ]: s = s + x + y s = 0 x = 5 y = 7 s = s + x + y y = 8 s = s + x + y x = 6 y = 7 s = s + x + y y = 8 s = s + x + y
Exercise: Convert speed • Making a speed conversion chart mph->kph • Chart the conversion: 10, 30, 40, 60, 75, 100mph • Print out example: 10mph 16.093kph • Now try it using one for loop! Much more concise!
Exercise: Create a log table using loop • Numbers: 1, 2, 4, 8, 10, 20, 40, 80, 100, 200, 400, 800, 1000 • Import - To not reinvent the wheel! - Use the console to check usage quickly!
Careful! • Don’t forget colon • Careful about the indentation
Today’s takeaway • Command line environment • Print • Loop