1 / 37

CISC 121 004 Fall 2012

CISC 121 004 Fall 2012. Instructor and Teaching Assistant. Instructor : Wendy Powley wendy@cs.queensu.ca Goodwin 632 http ://www.cs.queensu.ca/home/wendy Teaching Assistant : To be announced. Assistance.

quasim
Download Presentation

CISC 121 004 Fall 2012

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. CISC 121 004 Fall 2012

  2. Instructor and Teaching Assistant • Instructor: • Wendy Powley • wendy@cs.queensu.ca • Goodwin 632 • http://www.cs.queensu.ca/home/wendy • Teaching Assistant: • To be announced

  3. Assistance • 2 hour class on Monday – TA and instructor will be here – ask your questions! Please do NOT be shy. • Use your peers! • TA will hold office hours once we know who he/she is – these will be announced. • I don't have set office hours – you are free to contact me via email, use the question/answer board on the Moodle or set up a time to come to see me. • From time to time, I may offer small tutorial sessions on particular topics – if this is something you are interested in, please feel free to suggest it to me!

  4. Should you be in CISC 121? • CISC 121 assumes some programming knowledge • You should already know basics like: • variables • functions • data types – strings, integer, float • conditionals (if (x > 2) and NOT y then ....) • You should have experience writing some simple programs.

  5. Should you be in CISC 121? • Today’s class should be a review of concepts you have learned previously (although perhaps in a different programming language) • CISC 101 (or CISC 110) is for those with little to no programming knowledge. If today’s class seems difficult to you, or the homework is difficult, please consider switching classes. • Switching classes later in the term will be difficult! • CISC 101/110 use different programming language – it will be difficult to catch up if you leave it too late.

  6. CISC 121 – the “other” section • There are two sections of CISC 121 running concurrently. • They are NOT interchangeable!!! • Method of teaching will be different • Order of topics will be different • Different quizzes/assignments, marking scheme etc • However ... we are teaching all the same concepts. • You can still flee now --- but do so quickly!

  7. CISC 121 – Class Format • Monday 12:30 – 2:20 – held in Jeffery 155 • lots of hands-on activities • individual & pairs • assistance provided in class • COME PREPARED– readings DONE! • And be prepared to stay – this is NOT a drop-in “lab” – it is a class. • Thursday 8:30 – 9:20 – held in Jeffery 101 • more lecture style (fill in the gaps) • quizzes

  8. Marking Scheme ** if your final exam mark is less than 50%, your final will count as 80% of your mark (with assignments 8%, participation 2%, quizzes 10% )

  9. Homework • Homework assignments will be given weekly – beginning today. Due on Fridays at 12:00 noon. No exceptions! • with the exception of Thanksgiving week and the last week of class • Begin work in class on Monday – finish on your own during the week. • Its ok to work with others to solve problems (and I encourage it), however, please hand in your own work. Identical (or near identical) assignments will face penalties.

  10. Participation • 5% of your mark will be for participation • periodically during class I will ask you to do some activity – perhaps a survey, a short quiz or to upload some of your work. You will be marked on whether or not the task is done – not on its correctness. • SO.......if you are not in class, you will not have the opportunity to earn participation marks.

  11. Textbook Required book: • Python for Software Design: How to Think Like a Computer Scientist: Allen Downey Downey book can be downloaded on-line (see Moodle)

  12. Other Resources • Course notes (posted on-line) • Each week you will be asked to do some preparation prior to Monday’s class. This is mandatory – you must come to class prepared and ready to work. • Class time will be used for practical exercises -- short introductions to the topics may be given, but you are responsible for the in-depth learning on your own. • There are MANY other resources available – learn to seek them out!!! • This is one of the learning objectives of the course – resourcefulness!!!

  13. The Moodle • All course material can be found on the CISC 121 Moodle • Let’s go to the Moodle ... • http://moodle.queensu.ca • Please update your profile with your first name and a picture (when you can). • Check the calendar for quiz dates! • Watch for announcements during the term on the Moodle • I will send emails & put announcements at the top of the Moodle page.

  14. Programming Language/Environment Pythonis available in the Jeffery Lab – and available for download at: http://www.python.org/download/ Where does the Python name come from? Why Python? Python Version 2.7!!! (There are several versions on the lab computers – we will use 2.7). • be sure any reference material you use is Python 2, not Python 3 – there are many differences! IDLE IDE – we’ll use this in class. If you have another you prefer, please feel free to use it. http://wiki.python.org/moin/PythonEditors

  15. Course Content • Basics of programming in Python • Strings, lists, iterations, loops, nested loops, conditionals • Functions, scope • File I/O • Recursion • Searching, sorting • Complexity • Dictionaries • Linked Lists • Binary Search Trees • & program structure, good programming style, commenting, problem solving, debugging etc.

  16. Questions?

  17. Let’s try • Find Python 2.7 & start the IDLE IDE (Python GUI) • Write the requisite “Hello World” program in the Python Shell • Open a “New Window”, write the Hello World program, save it and run it. • Explore the IDLE configurations You will probably want to bring a flash drive to class to save your work on!

  18. Let’s try • Find Python 2.7 & start the IDLE IDE (Python GUI) • Write the requisite “Hello World” program in the Python Shell • Open a “New Window”, write the Hello World program, save it as hello.py and run it. • Explore the IDLE configurations You will probably want to bring a flash drive to class to save your work on!

  19. Download/Upload to Moodle • Download the class files for today & save them somewhere on your computer • NOTE that any files placed anywhere other than the D drive (or a flash drive that you bring with you) will be deleted when you log out! • Extract the files • Upload your hello.py to the Moodle.

  20. IDLE Editor • You will want to become comfortable with the IDLE editor – it will make your life easier! • Open ying_yang.py & run it. • ying_yang uses turtle graphics – research it if you want to know more. • Experiment with the various IDLE format commands. • check in the “Help -> IDLE help” to find out what some of the items mean. • Notice the different colours used by the editor. What do they mean?

  21. IDLE Editor • Notice the indentations • Select several lines in the “yin” function and use “indent region” to indent the selected lines. • save & run • If you’re waiting ... try changing the colors of ying_yang...or some of the calculations. Relative indentation is an important part of the Python language!

  22. Print Statement Try: print 7 print “Hello Put_your_name_here” print “I am ”, Put_your_age_here, “ years old” print 2 + 7 print 2 + 7, 1 + 1, 100 + 1 print 1,000,000 #what’s happening here? print 1; print 2 print “the result of 2 plus 3 plus 5 is”, 2+3+5 print evaluates each “expression” in turn and writes the resulting object to “standard output” (sdout) Strings may be quoted with double or single quotes – try it! You can even include a single quote in a double quoted string: Try printing: Welcome to Wendy’s!

  23. More on Print Put these lines into a file & run: print ‘End a print statement’ , print ‘with a comma and no new ’ , print ‘line will be added’ What happens if you cut & paste this into the IDLE window? Examine the errors – correct it!

  24. Arithmetic Expressions An arithmetic expression consists of operands (values) and operators (+ - * / ** %), and represents a numeric value Note: * = multiplication, / = division, ** = exponential % = modulo Try (in the python shell): 4 + 3 * 2 (4 + 3) * 22**3 11%2 #what’s this – try some more & see what happens 24%6 14%0 10/3 3/6 10.0/3 Are the results as you expected?

  25. Calculations on Strings • Try adding two strings together • Try multiplying two strings together • Try multiplying a string by a scalar number • Try dividing one string by another Remember the quotes around your strings!!!! print Dog + ‘house’ #what happens?

  26. Data Types • Every value has a type associated with it. • Some types: • String: “CISC 121” or ‘CISC 121’ • Integer: 99 • Floating Point (or “float”): 99.9 • Boolean: True/False

  27. Find out the type of a value: Try: • type(5) • type(“five”) • type(“5”) • type(5.2) • type([2, 3]) type() is a python function

  28. More Python functions Try these in the python interactive shell • print round(3.1453838, 2) • print round(3.1453838, 5) • print len(“hello”) • print len(‘#&$”*#((‘) • print len(‘’) Conversion functions convert values from one type to another: • int(‘32’) • str(32) • .......and others!

  29. Storing Information • Sometimes our program may need to remember information to be used later for example: • the result of a calculation • input from a user • input from some other source -- temperature from a web site, information read from a file, cost of a stock periodically taken over time (cost, timestamp) • .....

  30. Variables • Variables are locations in memory containing a value, labeled with a name • They are called “variables” because their contents can vary • We can store data in a variable • We can perform a calculation and store the results in a variable • We access stored values by using their variable names • Assignment Statements create new variables and gives them an initial value. • eg. x = 10 dog = “Fido”

  31. Variable names • should be meaningful • must begin with a letter • usually begin with a lowercase letter • can contain letters, numbers and underscores Cannot be one of Python’s keywords:

  32. Try: name = “Wendy” print name age = 27 print age print name, “is ”, age, “ years old” print “my age plus 10 is “, age + 10 print age age = age + 10 print age Try: p1 = “its the life in your years.” p2 = “years in your life that count, ” p3 = “In the end its not the “ Use these 3 variables to print out (in a single sentence), a wise saying.

  33. Be careful! zipcode = 01000 type(zipcode) print zipcode (???????) (to figure out what’s going on try 01, 011, 0100)

  34. Python is Dynamically Typed • Python is “dynamically typed” • This is different from most other languages where we state the type at declaration and variable type does not change. Try: name = “wendy” type (name) #note the type name = 100 type(name) #what type is it now? It has changed!!

  35. Simple Functions • A function is a named sequence of statements that can later be “called” from elsewhere in your program. • type() is a built-in function that we’ve used, but you can (and you will!!!) write your own fuctions.

  36. Sample Function Let’s write a simple function that prompts the user for the price of a meal and outputs the total amount of the meal with a 15% tip added. You should read about the differences between the “input()” and the raw_input() functions

  37. You try: Write a function that prompts the user for the length and width of a rectangle and outputs the perimeter and the area of the rectangle. ....the homework for this week begins here .

More Related