Practice with Lists and Strings CS303E: Elements of Computers and Programming.

Slides:



Advertisements
Similar presentations
Of.
Advertisements

The.
Exercise (1).
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.
Do I need a robot today? You only need a robot if your team has not shown me your octagon and/or the octagon in a function.
Exercises – don’t use built in functions for these as we want the practice Write a recursive function to add up all the numbers in a list "flatten" a list.
CS110 Programming Language I Lab 10: Arrays I Computer Science Department Spring 2014.
The.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
CS150 Introduction to Computer Science 1
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
Handling Errors Introduction to Computing Science and Programming I.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Main task -write me a program
JavaScript with Input & Output Step 1: Use tags JavaScript Template.
The fourth programming assignment J.-F. Pâris Fall 2014.
More Functions CS303E: Elements of Computers and Programming.
The if statement and files. The if statement Do a code block only when something is True if test: print "The expression is true"
Recursion.
Strings CS303E: Elements of Computers and Programming.
More While Loop Examples CS303E: Elements of Computers and Programming.
The.
CSE 201 – Elementary Computer Programming 1 Extra Exercises Source: Suggested but not selected midterm questions.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
More Functions with Return Values CS303E: Elements of Computers and Programming.
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
Count and add list of numbers From user input and from file.
More Strings CS303E: Elements of Computers and Programming.
 Problems  Rock-Paper-Scissors (fair game)  Functions Frenzy  Extra Problems  Pig Latin  Scoring Paper.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 7.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Loops and Simple Functions COSC Review: While Loops Typically used when the number of times the loop will execute is indefinite Typically used when.
For loop. Exercise 1 Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Lecture 9 For Loops.
Functions with Arguments and Return Values, Oh My! CS303E: Elements of Computers and Programming.
Functions CMSC 201 – Lab 5. Overview Objectives for today's lab:  Practice breaking down a program into multiple functions  Practice writing function.
Nested Loops CS303E: Elements of Computers and Programming.
Intro to CS Nov 21, 2016.
Do I need a robot today? You only need a robot if your team has not shown me your octagon and/or the octagon in a function.
CS1022 Computer Programming & Principles
© 2010 David A Watt, University of Glasgow
Chapter 2 Assignment and Interactive Input
Maha AlSaif Maryam AlQattan
Printing Lines of Asterisks
Topics Introduction to Repetition Structures
Review.
For Monday Read WebCT quiz 18.
L3. Necessary Java Programming Techniques
L3. Necessary Java Programming Techniques
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Spring 2010 EECS 110: Homework I.
Class Examples.
Text Analyzer BIS1523 – Lecture 14.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Writing Functions( ) (Part 4)
Introduction to Programming
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Lets Play with arrays Singh Tripty
CSE 1020:Software Development
Introduction to Programming
CS 1111 Introduction to Programming Spring 2019
Presentation transcript:

Practice with Lists and Strings CS303E: Elements of Computers and Programming

Question: Which code snippet evaluates to “f” if myString = “onafarm”? A. myString[4] B. myString.character(“f”) C. myString[-3] D. myString[3]

Question: What is the output? myMatrix = [[“he”, “she”, “it”], [“him”, “her”, “it”], [“his”, “hers”, “its”]] print myMatrix[2][1] A. himC. hers B. sheD. s

Question: myStr = raw_input(“Enter a name: “) printName(myStr) def printName(s): s=s.upper() s=s.upper() print myStr Assuming the user inputs “Sally”, what is the output? A. SallyC. Error B. SALLYD. myStr

Question: def f1(): x = 3 x = 3 x = 4 + x x = 4 + x def f2(): y = x*2 y = x*2 print y print y def main(): f1()f2()main() A. 7C. 21 B. 14D. Error

Group Exercise a) Create a main function that reads words from the user and places all words into a list. It should stop reading words when the user enters the empty string. b) Create a function that accepts a list of words and, for each word, finds the number of vowels. The number of vowels in each word should be placed in a list, so that the number of vowels is in the same element as the word it represents. Return the list of counts. c) Create a function that accepts a list of numbers and sums the numbers in the list. It should print the sum. d) In your main function, add code to call the function you created in (b) with the list of input, and code to accept its return value and then pass that data into the function you created in (c).