Python Programming for Beginners: CSSE 120 at Rose-Hulman Institute of Technology, Study notes of Software Engineering

Instructions for setting up idle for writing and running python programs, covers the basics of functions, saving and running programs, and an introduction to the software development process. It is a part of the csse 120 course at rose-hulman institute of technology.

Typology: Study notes

Pre 2010

Uploaded on 08/16/2009

koofers-user-72k
koofers-user-72k 🇺🇸

10 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
WRITING SIMPLE
PROGRAMS
CSSE 120—Rose-Hulman Institute of Technology
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Python Programming for Beginners: CSSE 120 at Rose-Hulman Institute of Technology and more Study notes Software Engineering in PDF only on Docsity!

WRITING SIMPLEPROGRAMS CSSE 120—Rose-Hulman Institute of Technology

Show Off Some Animations

Who would like me to show off their work?

Otherwise I’ll pick some programs at random

The Python Interpreter

What it does:^ †

Takes in Python commands

Converts them to 0s and 1s for the “CPU”

Gets answer back from “CPU”

How we’ll use it:^ †

IDLE’s Python

shell

—lets us “talk with” the interpreter

>>> is a Python

prompt

Q

Sequences of Statements

Functions^ †

Named sequences of statements

Can

invoke

them—make them run

Can take

parameters

—changeable parts

Defining vs. Invoking

Defining a function says what the function should do

Invoking a function makes that happen^ †

Parentheses tell interpreter to invoke the function

Later we’ll define functions with parameters

>>> hello() Hello I'd

like

to

complain

about

this

parrot

Q

Saving Programs

Annoying to keep retyping

Can save definitions in separate files^ †

Call

modules

or

scripts

In IDLE, use File

Æ

New Window

Can edit with plain old text editor (like Notepad)

Can use a

programming environment

Recognizes what you type

Tries to help

Examples: IDLE, Eclipse

Your .pyc is in my directory!

A partially translated version of your file

Called

byte code

Interpreter saves this to make loading faster

Try double-clicking it!

Breaking Down Chaos

A

simple

program

illustrating

chaotic

behavior.

# From Zelle, 1.6 def main():

print

"This

program

shows

a

chaotic

function"

x

input("Enter

a

number:

for

i

in

range(10):

x

x

x)

print

x

main()

comments Define a function called “main” A variable called x An input statement A loop The loop’s body Assignment statement Invoke function main

Q

Road Trip!

The Software Development Process

Analyze the Problem Determine Specifications Create a Design Implement the Design Test/Debug the Program Maintain the Program

Reserved Words

Built-in names

Can’t use as regular identifiers

Python reserved words:

and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass with def finally in print yield

Expressions

Fragments of code that produce or calculate newdata values

Examples^ †

Literals

: indicate a specific value

Identifiers

: evaluate to their assigned value

Compound

expressions using

operators

Can use parentheses to group

Q7-

Output Statements

Syntax:^ †

print

print

print , , …,

print , , …, ,

Semantics?

Is this allowed?^ †

print “The answer is:”, 7 * 3 * 2

A “slot” to be filled with any expression Repeat indefinitely Note: trailing comma

Q9-

Homework

Hand in Quiz

On Angel^ †

Lesson

Æ

Homework

Æ

Homework 2

Æ

Homework 2

Instructions

(or just follow link from Schedule page, that's what I do)