Presentation is loading. Please wait.

Presentation is loading. Please wait.

CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring 20151.

Similar presentations


Presentation on theme: "CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring 20151."— Presentation transcript:

1 CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring 20151

2 Announcements Reading, RQ 3 Due Assignment 1 due today, Assg 2 out! APT 1 is due on Thursday Finish lecture notes - last time for Sec 02 Today – more on functions, strings compsci 101, spring 20152

3 Python – Programming Concepts Names vs abstractions –What is http://152.3.140.1http://152.3.140.1 –What is http://www.amazon.comhttp://www.amazon.com Types are important –What is foo.pdf, foo.mp4, foo.jpg, foo.wav –Do the file extensions guarantee file type? Python – what types are these? first = "Susan" x = 6 y = 3.4 compsci 101, spring 20153

4 Strings Sequence of characters in quotes "I" + 'Love' + '''Python''' "I" 'Love' '''Python''' 'ILovePython' String operators: concatenation (+), repeat(*) Precedence? "a" + "b" + "c" * 3 'abccc' Precedence? "a" + "b" "c" * 3 'abcbcbc' 4compsci 101, spring 2015

5 Strings Sequence of characters in quotes (same result) "I" + 'Love' + '''Python''' "I" 'Love' '''Python''' 'ILovePython' String operators: concatenation (+), repeat(*) Precedence? "a" + "b" + "c" * 3 'abccc' Precedence? "a" + "b" "c" * 3 'abcbcbc' 5compsci 101, spring 2015

6 Function def functionName(parameters): block of code Parameters – place holder, will store value passed in Arguments – values in the call, that you pass to the function to use as input 6compsci 101, spring 2015

7 Function – return or print? Example function that returns a value def sum(a, b): return a+b Example function that prints def hw(name): print "Hello " + name Call Functions print sum(4,7) hw("Sue") 7compsci 101, spring 2015

8 Old MacDonald Song Write a Program to print this song compsci 101, spring 20158

9 Function OldMacPig() compsci 101, spring 20159

10 Rest of Code Function OldMacCow –Replace “pig” with “cow” –Replace “Oink” with “Moo” Code to start: compsci 101, spring 201510

11 Discuss how to make code better bit.ly/101S15-0120-01 Describe in words how you can make the code better? More efficient? –Fewer lines of code? –Use more functions? –Discuss your changes. What advantages do the changes you make have? compsci 101, spring 201511

12 OldMac3 bit.ly/101S15-0120-02 Describe what makes this version of OldMacDonald better than the first version compsci 101, spring 201512

13 OldMac3 - calls, and input passed pig OldMac main WithSound HadAnimal Refrain SayEIEIO OldMac Oink pig, Oink cow, Moo (rest not shown, similar to pic diagram) compsci 101, spring 201513


Download ppt "CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring 20151."

Similar presentations


Ads by Google