80 likes | 230 Views
CSCI 1001. overview of. computer science. PYTHON III. LISTS. are ordered sequences of values. students = [‘Carol’, ‘Bob’ , ‘Alice’, ‘Dave’]. ages = [20, 18, 17, 26]. students[1]. → ‘Bob’. ages[0]. → 20. ages = [20, 18, 17, 26]. for a in ages: print a. ages[1].
E N D
CSCI 1001 overview of computer science PYTHON III
LISTS are ordered sequences of values. students = [‘Carol’, ‘Bob’, ‘Alice’, ‘Dave’] ages = [20, 18, 17, 26] students[1] → ‘Bob’ ages[0] → 20
ages = [20, 18, 17, 26] for a in ages: print a ages[1] ages[1] = 19 #Happy Birthday! len(ages)
ages = [20, 18, 17, 26] ages.append(21) ages[1:3] more_ages = [23, 18, 19] ages + more_ages
ages = [20, 18, 17, 26] 17 in ages ages.index(17) sum(ages) range(0,10,2)
Acceptable Ages Function Take a list of pairs of ages (a,b). For each couple that is “creepy”, print a message saying the pair is creepy. At the end print out the number of couples that are not creepy.
Guessing Game Function Take a secret number as an argument. Ask user to guess it 3 times. Tell user whether guess is too low or high Congratulate them if they win! (Tell them the rules!)
http://cs1001.us/ Please read Sections 3-5 of the Python chapter for Friday