UW CSE 140 Section 1/10, Winter 2013
Find partners! Group can be 2-4 people. Try to share as much as possible about what you think with your teammates!
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. this text file to TA after class if you still feel doubt about any part of the section.
Command Prompt in Windows Terminal in Mac/Linux
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)
Using interpreter Using script – python myprogram.py – python myprogram.py argument1 argument2 The operating system command shell/prompt is not the same as the Python interpreter
Create a table using print about the simple info 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"
Careful about the conversion between number and string Use str(some number)
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?)
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 y in [ 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
Making a speed conversion chart mph->kph – Chart the conversion: 10, 30, 40, 60, 75, 100mph – Print out example: 10mph kph Now try it using one for loop! Much more concise!
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!
Don’t forget colon Careful about the indentation
Command line environment Print Loop