Intro to
Programming
(with Python)

Fall 2018
course
site

Any questions about the material in chapter 1 or the homework that you'd like to discuss?

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.

chap 2

software development cycle

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 in "pythontutori.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)

coming next : chap 3 - data types

The assignment for next Tue is posted ...

https://cs.marlboro.college /cours /fall2018 /python /notes /chap2
last modified Sat December 21 2024 6:11 pm