Intro to
Programming
(with Python)

Fall 2019
course
site

Tue Sep 10

Any questions about anything?

This week :

Tutoring!

running python

I'll do a few demos.

I can give access to jupyter.marlboro.college , including a shell, to anyone who wants that - let me know.

submitting homework

Depending on the assignment, typically you should turn in

The best way to submit work is through the course website - I'll do a demo of how this works.

If that isn't working, email me (mahoney@marlboro.edu) with your code as attachments.

Full credit for a homework assignment is "1.0". For a submission that only does some of what was assigned, especially if I can't see evidence of a real effort, you'll get a fraction of that. There's one term letter grade (A=excellent,B=good,C=fair) for all the homework together.

the big picture

Python programs can be written in several styles including imperative, object oriented, or functional. This term we'll be doing mostly the first two ... and a little of the third.

chapter 2

Some important ideas:

# an example of a function with an input
# Jim M | Sep 3 2018

def echo(message):
  print("you said '", message, "'.")

echo('Hello there')

Run this and discuss it.

software development cycle

variables

variables - named "boxes" to put data in

assignment statement (i.e. how to put data into a variable)

name = "Jim Mahoney"
age = 57
data = [2.3, 3.2, 16.23]

The part on the RIGHT is evaluated first. Then that is put INTO the thing on the left. Consider

x = x + 1

What is going on? Run this pythontutor.com to see.

example 1 : temperature convert

# convert.py
# A program to convert Celsius temps to Fahrenheit # by: Susan Computewell

def main():
    celsius = eval(input("What is the Celsius temperature? ")) 
    fahrenheit = 9/5 * celsius + 32
    print("The temperature is", farenheit, "degrees Fahrenheit.") 

main ()

example 2 : future value

# futval.py
# A program to compute the value of an investment 
# carried 10 years into the future

def main() : 
    print("This program calculates the future value") 
    print("of a 10-year investment.")
    principal = eval(input("Enter the initial principal: ")) 
    apr = eval(input("Enter the annual percent interest rate : "))
    for i in range(10):
        principal = principal * (1 + apr/100)
    print("The value in 10 years is: ", principal)

other stuff to discuss

coming next

https://cs.marlboro.college /cours /fall2019 /python /notes /chap2
last modified Fri December 13 2024 9:51 am