ECS15 sequence. Sequences  There are three kinds of sequences in Python: Strings – we use these a lot. “albatross” Lists – we saw those last time, they.

Slides:



Advertisements
Similar presentations
Course A201: Introduction to Programming 10/28/2010.
Advertisements

My Grandpa’s Farm Amber Fetherolf. My name is Sam. I am 7 years old and I love going to my grandpa’s farm. He has many different animals. He lets me feed.
1 Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 13.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
ECS15 for and sequence. Comments  Another way to repeat.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
Geography 465 Assignments, Conditionals, and Loops.
A R R A Y ! for Multiplication!!
VOCABULARY  Deck or pack  Suit  Hearts  Clubs  Diamonds  Spades  Dealer  Shuffle  Pick up  Rank  Draw  Set  Joker  Jack 
Guide to Programming with Python
Python Control of Flow.
April 2009 BEATING BLACKJACK CARD COUNTING FEASIBILITY ANALYSIS THROUGH SIMULATION.
Poker UML and ADT design plan.
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
AOIT Introduction to Programming Unit 3, Lesson 10 Advanced Sequence Manipulation Copyright © 2009–2012 National Academy Foundation. All rights reserved.
ECS 10 10/8. Outline Announcements Homework 2 questions Boolean expressions If/else statements State variables and avoiding sys.exit(…) Example: Coin.
Walk through previous lecture. TSP Questions: How many tours are there? How do you solve it? How fast can you solve it?
A Semantic Error in Google last weekend! Someone in Google typed an extra ‘/’ character into their URL List Link to CNN video report posted on Collab.
Guide to Programming with Python
Object Oriented Design. Object-Oriented Design Method for designing computer programs –Useful for thinking about large problems Consider “objects” interacting.
60 Questions (review for final exam) CSC 161: The Art of Programming Prof. Henry Kautz 12/7/
Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#
Built-in Data Structures in Python An Introduction.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Xin Liu Feb 4, * Use midterm questions for previous 231/217 midterms for practices * ams
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
November 28, 2005ICP: Chapter 9: Object Oriented Programming 1 Introduction to Computer Programming Chapter 9: Object Oriented Programming Michael Scherger.
Week 6 : Sequences ( lists, strings, and tuples ).
Xiaojuan Cai Computational Thinking 1 Lecture 8 Loop Structure Xiaojuan Cai (蔡小娟) Fall, 2015.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Lesson 65 Addition of Radical Expressions Weighted Average.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Chapter 10 Loops: while and for CSC1310 Fall 2009.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Y9 Booster Lesson 11. Pairs gameM11.1a A child’s game has two windows. In each window, one of three different animals – a bird, cat or dog – is equally.
Python Programing: An Introduction to Computer Science
Card Game Z  Agree on a dealer and a score keeper  The dealer should remove all the Jacks, Queens, Kings & Jokers from the pack and then shuffle  The.
Review: A Structural View program modules -> main program -> functions -> libraries statements -> simple statements -> compound statements expressions.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Guide to Programming with Python Chapter Four Strings, and Tuples; for Loops: The Word Jumble Game.
Unit 4 – Chapter 4 Strings and Tuples. len() Function You can pass any sequence you want to the len() function and it will return the length of the sequence.
Section 5.5 Application: The Card Game of War. 5.5 Application: The Card Game of War A deck of cards is shuffled and dealt to two players The players.
String and Lists Dr. José M. Reyes Álamo.
POKER-6S ooA, OOD, OOP.
Loops Upsorn Praphamontripong CS 1110 Introduction to Programming
Generating Random Numbers
Tuples and Lists.
Computer Programming Fundamentals
N Peakirk 2012 Presence of Animal Bone 5 Pig
Lesson 05: Iterations Class Chat: Attendance: Participation
Cookie Count The lesson Cookie Count from Maths 300 was based on the book “The Doorbell Rang” so to begin the unit we read the book and acted out the story.
ECS10 10/10
Basic operators - strings
Lecture 10 Data Collections
Dot Cards Face-Off Game
Introduction to Python
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Data Structures – 1D Lists
String and Lists Dr. José M. Reyes Álamo.
CS 1111 Introduction to Programming Spring 2019
The Data Element.
ECS15 boolean.
The Data Element.
Tuple.
Presentation transcript:

ECS15 sequence

Sequences  There are three kinds of sequences in Python: Strings – we use these a lot. “albatross” Lists – we saw those last time, they are important. [1,1,2,3,5,8,13] Tuples – a specialized kind of list: only does some of the things a list can, but does them more efficiently. We will ignore tuples in this course. (1,3,5,7,9)

Using sequences  We can concatenate sequences. “drive” + “way” has value “driveway” [1,2,3]+[3,2,1] = [1,2,3,3,2,1]

Looking for an item  Boolean expressions to test for the presence of an item: ‘i’ in ‘team’ 7 in range(1,7)

Using sequences  Use sequences in for loops for count in range(1,11): print count for animal in [“dog”, “cat”, “pig”, “cow”]: print “I love my”,animal

Shuffling!  Another random function in the random module random.shuffle(deck)  Takes the list deck and shuffles it.

Now to deal a hand…  deck[0] is the first item in the deck  deck[i] is the ith item in the deck  deck[51] is the last item (there are 52 cards in a deck)  deck[52] is an error!  deck[i], where i is the index.

How to avoid the error? len(deck) = 52 if i >= len(deck): print “Not a good index.” else: print “The”,str(i)+”th card is”,deck[i]

Dealing!  Dealer gets two cards  Player gets two cards  How do we decide who wins?

Need to know values  Make lists of values paralleling list of ranks  Look up value of rank of each card

Finally, add up score  My hand and your hand