 Problems  Rock-Paper-Scissors (fair game)  Functions Frenzy  Extra Problems  Pig Latin  Scoring Paper.

Slides:



Advertisements
Similar presentations
Lecture 03 – Sequences of data.  At the end of this lecture, students should be able to:  Define and use functions  Import functions from modules 
Advertisements

COMP 14 Introduction to Programming Mr. Joshua Stough February 16, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Introducing Loop Statements Liang, pages Loop statements control repeated execution of a block of statements Each time the statements in the block.
HW 1: Problems 3 & 4 EC 1 & 2.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
Practice for Midterm 1. Practice problems These slides have six programming problems for in-class practice There are an additional seven programming problems.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Chapter 4: Looping CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#6)
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Lecture 06 – Reading and Writing Text Files.  At the end of this lecture, students should be able to:  Read text files  Write text files  Example.
EECS 110: Lec 5: List Comprehensions Aleksandar Kuzmanovic Northwestern University
Working on exercises (a few notes first). Comments Sometimes you want to make a comment in the Python code, to remind you what’s going on. Python ignores.
CS 108 Computing Fundamentals Notes for Thursday, February 19, 2015.
Practice with Lists and Strings CS303E: Elements of Computers and Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
EECS 110: Lec 4: Functions and Recursion Aleksandar Kuzmanovic Northwestern University
Find the sum or difference. Then simplify if possible.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
Count and add list of numbers From user input and from file.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.
Variables, Types, Expressions Intro2CS – week 1b 1.
EECS 110: Lec 7: Program Planning Aleksandar Kuzmanovic Northwestern University
FILES. open() The open() function takes a filename and path as input and returns a file object. file object = open(file_name [, access_mode][, buffering])
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
The last CS 5 lecture you’ll ever need! Inducing labor for the machine! == Reducing labor for humans! On Warner Brothers' insistence, we affirm that this.
Exception Handling and String Manipulation. Exceptions An exception is an error that causes a program to halt while it’s running In other words, it something.
 1 Searching. Why searching? Searching is everywhere. Searching is an essential operation for a dictionary and other data structures. Understand the.
Loops (While and For) CSE 1310 – Introduction to Computers and Programming 1.
More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.
CS100 - PYTHON – EXAM 2 REVIEW -ONLY THE VITAL STUFF- PYTHON STRING METHODS, LOOPS, FILES, AND DICTIONARIES.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
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.
11 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
7 - Programming 7J, K, L, M, N, O – Handling Data.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Tuples and Lists.
Permutations and Combinations
CSc 110, Autumn 2017 Lecture 18: While loops and File Input
EECS 110: Lec 4: Functions and Recursion
Representing Characters
Another problem to solve…
Python I/O.
T. Jumana Abu Shmais – AOU - Riyadh
Permutations and Combinations
Another problem to solve…
CS 1111 Introduction to Programming Fall 2018
Spring 2010 EECS 110: Homework I.
Class Examples.
EECS 110: Lec 4: Functions and Recursion
Chapter 3: Selection Structures: Making Decisions
CHAPTER 6: Control Flow Tools (for and while loops)
Functions continued.
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Introduction to Computer Science
Chapter 3: Selection Structures: Making Decisions
Another problem to solve…
GCSE Computing.
Presentation transcript:

 Problems  Rock-Paper-Scissors (fair game)  Functions Frenzy  Extra Problems  Pig Latin  Scoring Paper

 Objective: Play rock-paper-scissors fairly  Steps for the program: 1. Choose the computer choice randomly (without revealing this value to the user) 2. Ask the user for their choice (give warning for incorrect choice) 3. Figure out the winner & print out the result

 Using choice function from random package  Example code: from random import * s = choice(['thread','yarn','twine']) print('I chose', s)

 Execute a block of code repeatedly as long as a condition is satisfied.  Application: Keep asking as long as incorrect choice is given by the user  Example code: answer = 'no' while answer == 'no': [body of the program] answer = input('Want to stop? ')

 Problems: 1. Multiplication: mult(n,m) 2. Dot product: dot(L,K) 3. First index: ind(e,L) 4. Scoring Letter*: letterScore(let) 5. Scoring Word: scrabbleScore(S)  Recursive Functions:  Base case  Recursive part

 Return: product of 2 integers  Requirements:  Use recursion  Use only: addition, subtraction, negation  Hints:  Use the construction of function power as a guide  m * n = m added together n times  Handling negative numbers

 Return: dot product of any 2 lists  Return 0.0 when  Lists have unequal lengths  Empty lists  Hints:  Use the construction of function mysum as a guide  Dot product = sum of products of elements in the same position  Example: [5,3] o [6,4] = 5*6 + 3*4 = 42

 Return: first index of an element in a list  Requirements  Use Recursion  Counting starts at 0  Nonexistence = return any integer ≥ len(L)  Examples: >>> ind(42, [55,77,42,12,42,100])‏ 2 >>> ind('i', 'team')‏ 4

 Return: score of a letter based on  Requirements  No recursion needed  Return 0 for input that is not from 'a' to 'z'  Hints:  Use in keyword: >>> 'a' in 'this is a string with letter a' True

 Return: score of a string  Requirements  Use recursion  Hints:  Use the construction of function mylen as a guide  Use letterScore(let) as previously defined

 The warm-up: pigLatin(s)  The challenge: spamLatin(s)

 Input: single word, lower letter string s  Translate to Pig Latin based on these rules  If s is an empty string: ▪ return an empty string  If s begins with a vowel (a,e,i,o,u) ▪ Append 'way' to the end of s ▪ Example: pigLatin('one') returns 'oneway'  If s begins with a consonant (the rest including y) ▪ Move this consonant to the end ▪ Then append 'ay' to the end ▪ Example: pigLatin('be') returns 'ebay'

 Input: single word, lower letter string s  Translate to Pig Latin based on these rules  If s is an empty string, or begins with a vowel, same with pigLatin(s)  If s begins with a consonant ▪ Move all initial consonants to the end ▪ Then append 'ay' to the end ▪ Example: pigLatin('string') returns 'ingstray'

 Rules (continue)  If s starts with 'y' which is followed by ▪ a vowel, then consider this 'y' to be a consonant ▪ a consonant, then consider this 'y' to be a vowel ▪ spamLatin('yttrium') returns 'yttriumway' ▪ spamLatin('yoohoo') returns 'oohooyay‘  Other cases: free to decide

 Input: a file name  Output:  Total Scrabble score  Total number of alphabetic characters  Average Scrabble-score-per-letter  Important: both upper- and lower-case letters

def printFileToScreen(fileName): f = open(fileName) text = f.read() f.close() print('The file contains:’) print() print(text)

 Recursive stack is limited at 1000 calls by default  Change this temporarily: import sys sys.setrecursionlimit(100000)‏

 Test on 2 additional files  Convert your files to plain text first  Include the results at the top of your program

 Name your files correctly  Include docstring for your functions  Test thoroughly Good luck