Class 8 – Friday, January 31

I know that or now I know that, that is the question

We are humankind — What a mantra that could be — I'm human and kind


Look both ways


Agenda


Downloads


To do list


Program temperature.py

f = 9/5 * c + 32

Enter Celsius temperature: 24

24 C = 75.2 F

24 C = 75 F

Enter Celsius temperature: 8

8 C = 46.4 F

8 C = 46 F

 


Program whats_the_point.py

Enter number: 3.14159265359

3.14159265359

3.14159

3.1416

3.142

3.14

3.1

3.0

3

Enter number: -3.14159265359

-3.14159265359

-3.14159

-3.1416

-3.142

-3.14

-3.1

-3.0

-3

Enter number: 4.998234

4.998234

4.99823

4.9982

4.998

5.0

5.0

5

5.0



Problem solving — chrestomathics

  • Prompts the user for a line of text.
  • Determines and prints the length of the text.
  • Determines and prints the last character of the text.

Two sample runs

Enter a line of text: Hoos got your back

The input has length: 18

The last character ( i.e., at index 17 ) is: k

Enter a line of text: And our winner is

The input has length: 17

The last character ( i.e., at index 16 ) is: s



Program kinda_stringy.py

Enter a three-letter string: abc

a

b

c

Enter a string: four score and seven

f

o

u

r

s

c

o

r

e

a

n

d

s

e

v

e

n

Enter a three-letter string: def

d

e

f

Enter a string: years ago our

y

e

a

r

s

a

g

o

o

u

r



Program amore.py

Some program runs

Enter three words: am or e

am

or

e

Enter several words: amor mapenzi amour liebe rakkaus

amor

mapenzi

amour

liebe

rakkaus

Enter three words: abcd efg hijklm

abcd

efg

hijklm

Enter several words: ljubav aroha ghaoil uthando

ljubav

aroha

ghaoil

uthando



Program again_and_again.py

Some program runs

Enter string to be printed: one more time

Enter number of times to be printed: 5

one more time

one more time

one more time

one more time

one more time

Enter string to be printed: I said how are you today

Enter number of times to be printed: 10

I said how are you today

I said how are you today

I said how are you today

I said how are you today

I said how are you today

I said how are you today

I said how are you today

I said how are you today

I said how are you today

I said how are you today



Homework manhattan_distance.py

  • Note: the program is to make only two prompts for data, each with two inputs on a single line, as demonstrated in the sample runs below.
  • The distance of a Manhattan city block running from one street to the next street is on average 1/20th of a mile.
  • The distance of a Manhattan city block running from one avenue to the next avenue is on average 3/20th of mile.

( 0.05 × | s1 – s2 | ) + ( 0.15 × | a1 – a2 | )

Two different sample runs

Starting corner (street and avenue): 59 6

Ending corner (street and avenue): 34 7

1.4

Starting corner (street and avenue): 47 2

Ending corner (street and avenue): 238 6

10.15


Problem for the interested student (and are you all not interested)

Two possible program runs

Enter three strings: a b c

Before the shift w1, w2, and w3 are respectively: a b c

After the shift w1, w2, and w3 are respectively: c a b

Enter three strings: kiwi cucumber nectarine

Before the shift w1, w2, and w3 are respectively: kiwi cucumber nectarine

After the shift w1, w2, and w3 are respectively: nectarine kiwi cucumber




{{Information |Description=Whitecliffs, Canterbury, New Zealand |Source=flickr.com ([http://www.flickr.com/photos/flissphil/148026511/]) |Date=16 May 2006 |Author=Phillip Capper |Permission= |other_versions= }}



street map nyc times square area

 


 
  © 2020 Jim Cohoon   Resources from previous semesters are available.