# Intro toProgramming(with Python)

Fall 2018
##### site

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

Some important ideas:

• functions
• function arguments (i.e. inputs)
• built-in print function (i.e. show on terminal)
# 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

• understand problem (can be harder than you think)
• create specification : inputs? outputs? (be very specific)
• choose algorithm: what is the recipe ?
• implement (write the code)
• test and debug (again, can be harder than you expect)
• maintain (if used over time, needs will usually change)

variables - named "boxes" to put data in

• legal names : x, yy23 the_data, this_is_a_long_name
• NOT legal : 3x (starts with number), x-y (no dashes), x.y (no periods)
• good names : principal, count, first_name
• not so good names: h (usually short), hpltz (too cryptic)

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 ()

• What is eval() ?
• What is input() ?
• Can you see how these two are nested inside each other?
• This program has a bug in in ...

## 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