1 / 20

UW CSE 140 Section

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.

palila
Download Presentation

UW CSE 140 Section

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UW CSE 140 Section 1/09, Winter 2014

  2. About me about you

  3. 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!

  4. 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.

  5. Command Lines Intro • Command Prompt in Windows • Terminal in Mac/Linux

  6. 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

  7. Change directory • cd Use “tab” to loop through path! • Make directory • mkdir(on unix, linux, osx) • md (on windows)

  8. 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

  9. 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"

  10. Exercise: Print a table • Careful about the conversion between number and string • Use str(some number)

  11. 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?)

  12. 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 )

  13. 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

  14. 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

  15. Exercise: Handout

  16. 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!

  17. 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!

  18. Careful! • Don’t forget colon • Careful about the indentation

  19. IDLE Questions?

  20. Today’s takeaway • Command line environment • Print • Loop

More Related