COSC 235: Programming and Problem Solving Ch. 2: Your first programs!!! Instructor: Dr. X.
-
Upload
clifford-wilson -
Category
Documents
-
view
213 -
download
0
Transcript of COSC 235: Programming and Problem Solving Ch. 2: Your first programs!!! Instructor: Dr. X.
COSC 235: Programming and Problem Solving
Ch. 2: Your first programs!!!Instructor: Dr. X
Goals
• Understand Input Process Output (IPO)
• Use variables• Understand expressions• Use and understand iteration
2
Software Development Process
• Analyze Problem – what?• Determine Specs - IO• Create Design – how?• Implement – make it• Test/Debug – break it • Maintain - …
Software Development Process
https://opensw.files.wordpress.com/2009/07/software_development1.jpg
Program Elements
• Names• Expressions• Input/Output
Names
• Make them meaningful (descriptive)• Camel case• Use _ to connect two words• Beware!– Symbols– Keywords– Case sensitive
Expressions
• Calculate new values<expr>
• Evaluate right hand side• Assign to left!• Spaces: are they important?
Output first… because it is easier
• Syntaxprint(<expr>, <expr>, …, <expr>)print()
• Semantics: display information (data)
Input is a little tougher…
• Syntax<variable> = input(<prompt>)<variable> = eval(input(<prompt>))
• Semantics?
Assignment
• Syntax<var> = <expr>
• Semantics?• Have we seen this before?
Simultaneous assignment
• Syntax<var>, <var>, …, <var> = <expr>, <expr>, …, <expr>
• Exercise: Write a sequence of assignment statements that exchange the values of thing1 & thing2
http://www.cliparthut.com/thing-1-and-2-dr-seuss-clipart-UnZOY3.html
Exercise
• Print “Hello world” 10 times, then print it 100 times…
• Print the integer numbers from 0..10, 0..100
Loops
https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Shockwave_coaster_sfot.jpg/220px-Shockwave_coaster_sfot.jpg
http://3.bp.blogspot.com/-eYwYLrlLWZs/UNlpG3goYgI/AAAAAAAACaI/MdQ2-CPcJYY/s1600/01.gif
http://img1.wikia.nocookie.net/__cb20110112235951/logopedia/images/0/0a/Froot_Loops_logo.jpg
Loops
• Syntaxfor <var> in <sequence>:
<body>
• Semantics: avoid doing repetitive things using copy paste =) OR execute a definite sequence of steps
References
• “Python Programming: An Introduction to Computer Science”, 2nd ed., John M. Zelle