How do sort this list using one line? a_list.sort()

Size: px
Start display at page:

Download "How do sort this list using one line? a_list.sort()"

Transcription

1 Review Questions for lists and File (read and write): Make sure to review Midterm 1 and midterm 2, all samples for midterms as well. Review all of the homework, class examples and readings exercises. Make sure to do the readings as well and review all of the class notes. 1) Given: >>> a_list = ["a", "b", "c", "d", "e", "f"] >>> a_list[1:3] ['b', 'c'] >>> a_list[:4] ['a', 'b', 'c', 'd'] >>> a_list[3:] ['d', 'e', 'f'] >>> a_list[:] ['a', 'b', 'c', 'd', 'e', 'f'] >>> a_list[- 1] [ 'f'] >>> a_list[::- 1] ['f', 'e', 'd','c', 'b', a'] How do sort this list using one line? a_list.sort()

2 How do you reverse the list using one line? a_list.reverse() How do you add the value 7 to the end of the list? a_list.append(7) How do you find in element a exists in list? If a in a_list: How do you count how many times the value c exists? print(a list.count( f )) How do you remove the value d from list? a_list.remove( d ) How do you find the length of the list? Len(a_list)

3 Write the following programs: 1) Call a function to initialize a list randomly (values should be between 1 and 100 inclusive and these values should be divisible evenly by 3 and 5. Then print the list. import random def rand(list): for i in range(1,101,1): # only select random numbers divisible evenly by 3 & 5 if (i%3 ==0 and i%5 ==0): list.append(random.randint(1,10)) print("list in rand function: ", list) def total(list): ''' function to print and compute total of elements in a list ''' tot=0 for item in list: tot += item print("total is: ", tot) num =[] print("list in main: ", num) rand(num)# you are now passing the address in memory where list is stored print("list in main: ", num) total(num)# compute total for all list values/elements

4 2) Read a list of words from file, and then search to see if that list includes the word Python. Count how many times Python appears in the file. If the word python appeared in the file, then write python and the number of times the word python appeared into a file? def searchfile(oldfile, newfile): f1 = open(oldfile, "r") f2 = open(newfile, "w") count=0 while True: text = f1.readline() if text == "": break if ("python" in text or "Python" in text): count += 1 f2.write(text) # if you find python then write it to file if count > 0: # print the count of Python in file f2.write("the number of times python appeared in file is : " + str( count) + "\n") f1.close() f2.close() oldfile = "languages.txt" newfile = 'python.txt' searchfile(oldfile, newfile)

5 3) [Sale application] Write a program that will call a function to decrease all of the list elements values (prices) by 40% when the items are on sale. Then call another function to increase all of the list elements values (prices) by 40% when the sale is over. prices = [100,20,50] print ("Prices from main before function call: ", prices) bf(prices) print ("Prices from main after function bf call: ", prices) orig(prices) print ("Prices from main before function orig call: ", prices) def bf(prices): for i in range (len(prices)): prices[i]= prices[i] *.6 def orig(prices): for i in range (len(prices)): prices[i]= prices[i]/.6

6 4) Ask the user to enter integers 1 to 12 for the month. Then, print the month such as January if the user entered 1 and December if the user entered 12. import random monthnumber = input('enter the month using a number from 1-12: ') mnumber= int(monthnumber) months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Oct','November', 'December'] print('you picked: '+ printmonth(months,mnumber)) # Select a month at random from months list randommonth = pickrandommonth(months) print("month picked at random is: ", randommonth) def printmonth(months, mnumber): if mnumber < 1 or mnumber > 12: month = 'Error ' else: month = months[mnumber - 1] return month def pickrandommonth(months): rnum = random.randint(1, (len(months)- 1)) ranmonth = months[rnum] return ranmonth

7 5) Select a word from a list randomly and then ask the user to guess it in three trials. Make sure to give hints on the 2 nd and third trials such as the length of the string and the first character of the word. ''' read files a list of words and then assign all of the words to a list and then choose one word at random from the list. Then play a guess the secret word game in three trials. ''' import random names=[] #Global list # function to read words from file and assign it to a list def readfile(myfile): # read file myfile = open(myfile, "r") for line in myfile: name=line.rstrip('\n') names.append(name) def game(word): #play guess the secret word in 3 trials trial =1 secret="" secret= word.lower() keepgoing= True while(keepgoing): guess = input("try to guess the secret word: ") if ((guess.lower()) == secret): print("congratulations! You won in: ", trial, " trials") keepgoing = False break else:

8 if trial == 3: print("sorry! You lost the game. You used all your three chances", ". The secret word is: ", word) keepgoing = False break else: print("you have ", (3- trial), " trials remaining!") trial += 1 # function to select one word at random from list def selectrandom(): word = random.choice(names) print("word is :", word) return word # printing words.txt (names) print() #call function to read from file words.txt readfile('words.txt') #call function to select a word at random from list word = selectrandom() game(word)

Programming Exercises

Programming Exercises s CMPS 5P (Professor Theresa Migler-VonDollen ): Assignment #8 Problem 6 Problem 1 Programming Exercises Modify the recursive Fibonacci program given in the chapter so that it prints tracing information.

More information

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID:

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID: CS177 MIDTERM 2 PRACTICE EXAM SOLUTION Name: Student ID: This practice exam is due the day of the midterm 2 exam. The solutions will be posted the day before the exam but we encourage you to look at the

More information

Beginning to Program Python

Beginning to Program Python COMP1021 Introduction to Computer Science Beginning to Program Python David Rossiter Outcomes After completing this presentation, you are expected to be able to: 1. Use Python code to do simple text input

More information

Computer Science for San Francisco Youth

Computer Science for San Francisco Youth Python for Beginners Python for Beginners Lesson 0. A Short Intro Lesson 1. My First Python Program Lesson 2. Input from user Lesson 3. Variables Lesson 4. If Statements How If Statements Work Structure

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1-5.2 self-check: #8-17 exercises: #3-6, 10, 12 videos: Ch. 5 #1-2 1 The Random class A Random object generates pseudo-random* numbers.

More information

Webair CDN Secure URLs

Webair CDN Secure URLs Webair CDN Secure URLs Webair provides a URL signature mechanism for securing access to your files. Access can be restricted on the basis of an expiration date (to implement short-lived URLs) and/or on

More information

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output CSCE 110 Programming Basics of Python: Variables, Expressions, and nput/output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Fall 2011 Python Python was developed

More information

Python for Rookies. Example Examination Paper

Python for Rookies. Example Examination Paper Python for Rookies Example Examination Paper Instructions to Students: Time Allowed: 2 hours. This is Open Book Examination. All questions carry 25 marks. There are 5 questions in this exam. You should

More information

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to Chapter 3 Writing Simple Programs Charles Severance Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/.

More information

Sorting. Lists have a sort method Strings are sorted alphabetically, except... Uppercase is sorted before lowercase (yes, strange)

Sorting. Lists have a sort method Strings are sorted alphabetically, except... Uppercase is sorted before lowercase (yes, strange) Sorting and Modules Sorting Lists have a sort method Strings are sorted alphabetically, except... L1 = ["this", "is", "a", "list", "of", "words"] print L1 ['this', 'is', 'a', 'list', 'of', 'words'] L1.sort()

More information

Compsci 101: Test 1. October 2, 2013

Compsci 101: Test 1. October 2, 2013 Compsci 101: Test 1 October 2, 2013 Name: NetID/Login: Community Standard Acknowledgment (signature) Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 TOTAL: value 16 pts. 12 pts. 20 pts. 12 pts. 20 pts.

More information

NLP Lab Session Week 3 Bigram Frequencies and Mutual Information Scores in NLTK September 16, 2015

NLP Lab Session Week 3 Bigram Frequencies and Mutual Information Scores in NLTK September 16, 2015 NLP Lab Session Week 3 Bigram Frequencies and Mutual Information Scores in NLTK September 16, 2015 Starting a Python and an NLTK Session Open a Python 2.7 IDLE (Python GUI) window or a Python interpreter

More information

Computer Science 217

Computer Science 217 Computer Science 217 Midterm Exam Fall 2009 October 29, 2009 Name: ID: Instructions: Neatly print your name and ID number in the spaces provided above. Pick the best answer for each multiple choice question.

More information

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

System.out.println(\nEnter Product Number 1-5 (0 to stop and view summary) : Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class

More information

Exercise 4 Learning Python language fundamentals

Exercise 4 Learning Python language fundamentals Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also

More information

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input

More information

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

More information

F ahrenheit = 9 Celsius + 32

F ahrenheit = 9 Celsius + 32 Problem 1 Write a complete C++ program that does the following. 1. It asks the user to enter a temperature in degrees celsius. 2. If the temperature is greater than 40, the program should once ask the

More information

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals: Numeral Systems Which number is larger? 25 8 We need to distinguish between numbers and the symbols that represent them, called numerals. The number 25 is larger than 8, but the numeral 8 above is larger

More information

Python 3 Programming. OCR GCSE Computing

Python 3 Programming. OCR GCSE Computing Python 3 Programming OCR GCSE Computing OCR 2012 1 Contents Introduction 3 1. Output to the screen 5 2. Storing Data in Variables 6 3. Inputting Data 8 4. Calculations 9 5. Data Types 10 6. Selection with

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

Introduction to: Computers & Programming: Review for Midterm 2

Introduction to: Computers & Programming: Review for Midterm 2 Introduction to: Computers & Programming: Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in the Class The Practice Midterm

More information

Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue?

Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue? Python KS3 Programming Workbook Do you speak Parseltongue? Name ICT Teacher Form Welcome to Python The python software has two windows that we will use. The main window is called the Python Shell and allows

More information

Algorithm Design and Recursion

Algorithm Design and Recursion Chapter 13 Algorithm Design and Recursion Objectives To understand basic techniques for analyzing the efficiency of algorithms. To know what searching is and understand the algorithms for linear and binary

More information

Outline Basic concepts of Python language

Outline Basic concepts of Python language Data structures: lists, tuples, sets, dictionaries Basic data types Examples: int: 12, 0, -2 float: 1.02, -2.4e2, 1.5e-3 complex: 3+4j bool: True, False string: "Test string" Conversion between types int(-2.8)

More information

Introduction to Python for Text Analysis

Introduction to Python for Text Analysis Introduction to Python for Text Analysis Jennifer Pan Institute for Quantitative Social Science Harvard University (Political Science Methods Workshop, February 21 2014) *Much credit to Andy Hall and Learning

More information

6.090, IAP 2005 Lecture 8

6.090, IAP 2005 Lecture 8 1 MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.090 Building Programming Experience IAP 2005 Lecture 8 Tags ; professor abstraction (define (make professor

More information

Lab 5: HTTP Web Proxy Server

Lab 5: HTTP Web Proxy Server Lab 5: HTTP Web Proxy Server In this lab, you will learn how web proxy servers work and one of their basic functionalities caching. Your task is to develop a small web proxy server which is able to cache

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control Reading: Bowman, Chapters 16 CODE BLOCKS A code block consists of several lines of code contained between a BEGIN

More information

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.

More information

Program to solve first and second degree equations

Program to solve first and second degree equations Fundamentals of Computer Science 010-011 Laboratory 4 Conditional structures () Objectives: Design the flowchart of programs with conditional sentences Implement VB programs with conditional sentences

More information

Term Project: Roulette

Term Project: Roulette Term Project: Roulette DCY Student January 13, 2006 1. Introduction The roulette is a popular gambling game found in all major casinos. In contrast to many other gambling games such as black jack, poker,

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Changing the Display Frequency During Scanning Within an ImageControls 3 Application

Changing the Display Frequency During Scanning Within an ImageControls 3 Application Changing the Display Frequency During Scanning Within an ImageControls 3 Date November 2008 Applies To Kofax ImageControls 2x, 3x Summary This application note contains example code for changing he display

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information

transmission media and network topologies client/server architecture layers, protocols, and sockets

transmission media and network topologies client/server architecture layers, protocols, and sockets Network Programming 1 Computer Networks transmission media and network topologies client/server architecture layers, protocols, and sockets 2 Network Programming a simple client/server interaction the

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

if and if-else: Part 1

if and if-else: Part 1 if and if-else: Part 1 Objectives Write if statements (including blocks) Write if-else statements (including blocks) Write nested if-else statements We will now talk about writing statements that make

More information

Iteration CHAPTER 6. Topic Summary

Iteration CHAPTER 6. Topic Summary CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many

More information

Introduction to Computer Science I Spring 2014 Mid-term exam Solutions

Introduction to Computer Science I Spring 2014 Mid-term exam Solutions Introduction to Computer Science I Spring 2014 Mid-term exam Solutions 1. Question: Consider the following module of Python code... def thing_one (x): y = 0 if x == 1: y = x x = 2 if x == 2: y = -x x =

More information

South East of Process Main Building / 1F. North East of Process Main Building / 1F. At 14:05 April 16, 2011. Sample not collected

South East of Process Main Building / 1F. North East of Process Main Building / 1F. At 14:05 April 16, 2011. Sample not collected At 14:05 April 16, 2011 At 13:55 April 16, 2011 At 14:20 April 16, 2011 ND ND 3.6E-01 ND ND 3.6E-01 1.3E-01 9.1E-02 5.0E-01 ND 3.7E-02 4.5E-01 ND ND 2.2E-02 ND 3.3E-02 4.5E-01 At 11:37 April 17, 2011 At

More information

CSIS 202: Introduction to Computer Science Spring term 2015-2016 Midterm Exam

CSIS 202: Introduction to Computer Science Spring term 2015-2016 Midterm Exam Page 0 German University in Cairo April 7, 2016 Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Hisham Othman CSIS 202: Introduction to Computer Science Spring term 2015-2016 Midterm Exam

More information

Systems Programming & Scripting

Systems Programming & Scripting Systems Programming & Scripting Lecture 14 - Shell Scripting: Control Structures, Functions Syst Prog & Scripting - Heriot Watt University 1 Control Structures Shell scripting supports creating more complex

More information

Python Objects. Charles Severance www.pythonlearn.com. http://en.wikipedia.org/wiki/object-oriented_programming

Python Objects. Charles Severance www.pythonlearn.com. http://en.wikipedia.org/wiki/object-oriented_programming Python Objects Charles Severance www.pythonlearn.com http://en.wikipedia.org/wiki/object-oriented_programming Warning This lecture is very much about definitions and mechanics for objects This lecture

More information

Introduction to. Marty Stepp (stepp@cs.washington.edu) University of Washington

Introduction to. Marty Stepp (stepp@cs.washington.edu) University of Washington Introduction to Programming with Python Marty Stepp (stepp@cs.washington.edu) University of Washington Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except

More information

PYTHON Basics http://hetland.org/writing/instant-hacking.html

PYTHON Basics http://hetland.org/writing/instant-hacking.html CWCS Workshop May 2009 PYTHON Basics http://hetland.org/writing/instant-hacking.html Python is an easy to learn, modern, interpreted, object-oriented programming language. It was designed to be as simple

More information

Chapter 11. Talk To Your Computer

Chapter 11. Talk To Your Computer Chapter 11. Talk To Your Computer One of the more interesting things about the Logo language is list processing. Early computer languages were known as "number crunchers." Everything was represented by

More information

from Recursion to Iteration

from Recursion to Iteration from Recursion to Iteration 1 Quicksort Revisited using arrays partitioning arrays via scan and swap recursive quicksort on arrays 2 converting recursion into iteration an iterative version with a stack

More information

Software Testing. Theory and Practicalities

Software Testing. Theory and Practicalities Software Testing Theory and Practicalities Purpose To find bugs To enable and respond to change To understand and monitor performance To verify conformance with specifications To understand the functionality

More information

HTSQL is a comprehensive navigational query language for relational databases.

HTSQL is a comprehensive navigational query language for relational databases. http://htsql.org/ HTSQL A Database Query Language HTSQL is a comprehensive navigational query language for relational databases. HTSQL is designed for data analysts and other accidental programmers who

More information

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65 Simulation Tools Python for MATLAB Users I Claus Führer Automn 2009 Claus Führer Simulation Tools Automn 2009 1 / 65 1 Preface 2 Python vs Other Languages 3 Examples and Demo 4 Python Basics Basic Operations

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 5 Lecture 5-3: Boolean Logic reading: 5.2 self-check: #11-17 exercises: #12 videos: Ch. 5 #2 1 while loop question Write a method named digitsum that accepts an integer as

More information

CS170 Lab 11 Abstract Data Types & Objects

CS170 Lab 11 Abstract Data Types & Objects CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the

More information

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control ESCI 386 Scientific Programming, Analysis and Visualization with Python Lesson 5 Program Control 1 Interactive Input Input from the terminal is handled using the raw_input() function >>> a = raw_input('enter

More information

Project 2: Web Security Pitfalls

Project 2: Web Security Pitfalls EECS 388 September 19, 2014 Intro to Computer Security Project 2: Web Security Pitfalls Project 2: Web Security Pitfalls This project is due on Thursday, October 9 at 6 p.m. and counts for 8% of your course

More information

Chapter 2 Writing Simple Programs

Chapter 2 Writing Simple Programs Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle Software Development Process Figure out the problem - for simple problems

More information

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing. Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Automating SQL Injection Exploits

Automating SQL Injection Exploits Automating SQL Injection Exploits Mike Shema IT Underground, Berlin 2006 Overview SQL injection vulnerabilities are pretty easy to detect. The true impact of a vulnerability is measured

More information

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors. The Prime Numbers Before starting our study of primes, we record the following important lemma. Recall that integers a, b are said to be relatively prime if gcd(a, b) = 1. Lemma (Euclid s Lemma). If gcd(a,

More information

Database trends: XML data storage

Database trends: XML data storage Database trends: XML data storage UC Santa Cruz CMPS 10 Introduction to Computer Science www.soe.ucsc.edu/classes/cmps010/spring11 ejw@cs.ucsc.edu 25 April 2011 DRC Students If any student in the class

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

AP Computer Science A 2011 Free-Response Questions

AP Computer Science A 2011 Free-Response Questions AP Computer Science A 2011 Free-Response Questions About the College Board The College Board is a mission-driven not-for-profit organization that connects students to college success and opportunity. Founded

More information

Software Development. Chapter 7. Outline. 7.1.1 The Waterfall Model RISKS. Java By Abstraction Chapter 7

Software Development. Chapter 7. Outline. 7.1.1 The Waterfall Model RISKS. Java By Abstraction Chapter 7 Outline Chapter 7 Software Development 7.1 The Development Process 7.1.1 The Waterfall Model 7.1.2 The Iterative Methodology 7.1.3 Elements of UML 7.2 Software Testing 7.2.1 The Essence of Testing 7.2.2

More information

Outline. multiple choice quiz bottom-up design. the modules main program: quiz.py namespaces in Python

Outline. multiple choice quiz bottom-up design. the modules main program: quiz.py namespaces in Python Outline 1 Modular Design multiple choice quiz bottom-up design 2 Python Implementation the modules main program: quiz.py namespaces in Python 3 The Software Cycle quality of product and process waterfall

More information

Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

More information

Introduction to Python

Introduction to Python 1 Daniel Lucio March 2016 Creator of Python https://en.wikipedia.org/wiki/guido_van_rossum 2 Python Timeline Implementation Started v1.0 v1.6 v2.1 v2.3 v2.5 v3.0 v3.1 v3.2 v3.4 1980 1991 1997 2004 2010

More information

HowThe Most Effective Way To Get Rich Fast!

HowThe Most Effective Way To Get Rich Fast! !"#$%&'()%*+,,,!-'()%*./+&012'%3"#$%3&'()%*!4-'()%*./+,,,!-'(5%./+677!4-'(5%./+,,,!)(*890':#*9-+,,,,,!)(*980':#*9+!;01%+!4;01%+!4)(*980':#*9+,,,!4)(*890':#*9-+,,,!5#12#;%;9-+,,,,,!"#$%&'()%*>#12#;%;9+,,,,,,,!;01%+?:!4;01%+,,,,,,,!9@2%+?0-9:09A3=0*%B%90'!49@2%+,,,,,,,!-8C9@2%+DB.!4-8C9@2%+,,,,,,,!(;9%*E05%-+,,,,,,,,,!;81FE.;9%*E05%-+G!4;81FE.;9%*E05%-+,,,,,,,!4(;9%*E05%-+,,,,,,,!*%-#8*5%+,,,,,,,,,!528+6!4528+,,,,,,,,,!5281#$%+$%$(509%$!45281#$%+,,,,,,,,,!1%1#*@,8;(9HIB=I+JGK!41%1#*@+,,,,,,,!4*%-#8*5%+,,,,,,,!20*01%9%*-+,,,,,,,,,!C##9.10L%+A992M44%N012'%O5#14DB.3C(;0*@,!4C##9.10L%+,,,,,,,,,!C##9:0*01-4+,,,,,,,!420*01%9%*-+,,,,,!4"#$%&'()%*>#12#;%;9+,,,,,!"#$%&'()%*>#12#;%;9+,,,,,,,!;01%+&:!4;01%+,,,,,,,!9@2%+&'#P:09A3QB!49@2%+,,,,,,,!-8C9@2%+RQB!4-8C9@2%+,,,,,,,!(;9%*E05%-+,,,,,,,,,!;81FE.;9%*E05%-+J!4;81FE.;9%*E05%-+,,,,,,,!4(;9%*E05%-+,,,,,,,!*%-#8*5%+,,,,,,,,,!528+6!4528+,,,,,,,,,!5281#$%+$%$(509%$!45281#$%+,,,,,,,,,!1%1#*@,8;(9HI=I+J7ST!41%1#*@+,,,,,,,!4*%-#8*5%+,,,,,,,!20*01%9%*-+,,,,,,,,,!C##9.10L%+A992M44%N012'%O5#14RQB3$(-UO(1L,!4C##9.10L%+,,,,,,,,,!C##9:0*01-4+,,,,,,,!420*01%9%*-+,,,,,!4"#$%&'()%*>#12#;%;9+,,,!45#12#;%;9-+,,,!5#;;%59(#;B02+,,,,,!"#$%>#;;%59(#;,9@2%HI:V9#V:I+,,,,,,,!-#8*5%+,,,,,,,,,!Q(*980'.;9%*E05%+,,,,,,,,,,,!5#12#;%;9+3Q:FDW3!45#12#;%;9+,,,,,,,,,,,!(;9%*E05%+!4(;9%*E05%+,,,,,,,,,!4Q(*980'.;9%*E05%+,,,,,,,!4-#8*5%+,,,,,,,!$%-9(;09(#;+,,,,,,,,,!Q(*980'.;9%*E05%+,,,,,,,,,,,!5#12#;%;9+?0-9:09A!45#12#;%;9+,,,,,,,,,,,!(;9%*E05%+J!4(;9%*E05%+,,,,,,,,,!4Q(*980'.;9%*E05%+,,,,,,,!4$%-9(;09(#;+,,,,,,,!C($(*+WDXY!4C($(*+,,,,,!4"#$%>#;;%59(#;+,,,,,!"#$%>#;;%59(#;,9@2%HI&P(95AI+,,,,,,,!Q(*980'.;9%*E05%+,,,,,,,,,!5#12#;%;9+?0-9:09A!45#12#;%;9+,,,,,,,,,!(;9%*E05%+Z!4(;9%*E05%+,,,,,,,!4Q(*980'.;9%*E05%+,,,,,,,!Q(*980'.;9%*E05%+,,,,,,,,,!5#12#;%;9+?0-9:09A!45#12#;%;9+,,,,,,,,,!(;9%*E05%+S!4(;9%*E05%+,,,,,,,!4Q(*980'.;9%*E05%+,,,,,,,!Q(*980'.;9%*E05%+,,,,,,,,,!5#12#;%;9+&'#P:09A!45#12#;%;9+,,,,,,,,,!(;9%*E05%+7!4(;9%*E05%+,,,,,,,!4Q(*980'.;9%*E05%+,,,,,,,!Q(*980'.;9%*E05%+,,,,,,,,,!5#12#;%;9+&'#P:09A!45#12#;%;9+,,,,,,,,,!(;9%*E05%+6!4(;9%*E05%+,,,,,,,!4Q(*980'.;9%*E05%+,,,,,!4"#$%>#;;%59(#;+,,,!45#;;%59(#;B02+,,,!20*01%9%*-+,,,,,!089AR%@+=0-%KS3Y;5#$%$3&-AR%@?('%!4089AR%@+,,,!420*01%9%*-+,!4"#$%&'()%*+,

More information

Computational Mathematics with Python

Computational Mathematics with Python Boolean Arrays Classes Computational Mathematics with Python Basics Olivier Verdier and Claus Führer 2009-03-24 Olivier Verdier and Claus Führer Computational Mathematics with Python 2009-03-24 1 / 40

More information

CSC 180 H1F Algorithm Runtime Analysis Lecture Notes Fall 2015

CSC 180 H1F Algorithm Runtime Analysis Lecture Notes Fall 2015 1 Introduction These notes introduce basic runtime analysis of algorithms. We would like to be able to tell if a given algorithm is time-efficient, and to be able to compare different algorithms. 2 Linear

More information

UI Backend Database and other shared resources Plan Develop Test Report Database Backend Frontend Customers 200 600 1200 3000 6000 10000 RTUs 400 1200 2400 6000 12000 20000 Devices 1300 3900

More information

PHP Magic Tricks: Type Juggling. PHP Magic Tricks: Type Juggling

PHP Magic Tricks: Type Juggling. PHP Magic Tricks: Type Juggling Who Am I Chris Smith (@chrismsnz) Previously: Polyglot Developer - Python, PHP, Go + more Linux Sysadmin Currently: Pentester, Consultant at Insomnia Security Little bit of research Insomnia Security Group

More information

Pseudo code Tutorial and Exercises Teacher s Version

Pseudo code Tutorial and Exercises Teacher s Version Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Social Science Research Lab American University, Washington, D.C. Web. www.american.edu/provost/ctrl/pclabs.cfm Tel. x3862 Email. SSRL@American.edu Course Objective This course provides

More information

Feb 7 Homework Solutions Math 151, Winter 2012. Chapter 4 Problems (pages 172-179)

Feb 7 Homework Solutions Math 151, Winter 2012. Chapter 4 Problems (pages 172-179) Feb 7 Homework Solutions Math 151, Winter 2012 Chapter Problems (pages 172-179) Problem 3 Three dice are rolled. By assuming that each of the 6 3 216 possible outcomes is equally likely, find the probabilities

More information

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

EE 261 Introduction to Logic Circuits. Module #2 Number Systems EE 261 Introduction to Logic Circuits Module #2 Number Systems Topics A. Number System Formation B. Base Conversions C. Binary Arithmetic D. Signed Numbers E. Signed Arithmetic F. Binary Codes Textbook

More information

Loop Invariants and Binary Search

Loop Invariants and Binary Search Loop Invariants and Binary Search Chapter 4.3.3 and 9.3.1-1 - Outline Ø Iterative Algorithms, Assertions and Proofs of Correctness Ø Binary Search: A Case Study - 2 - Outline Ø Iterative Algorithms, Assertions

More information

Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

Computational Mathematics with Python

Computational Mathematics with Python Computational Mathematics with Python Basics Claus Führer, Jan Erik Solem, Olivier Verdier Spring 2010 Claus Führer, Jan Erik Solem, Olivier Verdier Computational Mathematics with Python Spring 2010 1

More information

Introduction to Python

Introduction to Python Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

More information

Lecture 2, Introduction to Python. Python Programming Language

Lecture 2, Introduction to Python. Python Programming Language BINF 3360, Introduction to Computational Biology Lecture 2, Introduction to Python Young-Rae Cho Associate Professor Department of Computer Science Baylor University Python Programming Language Script

More information

CSC 221: Computer Programming I. Fall 2011

CSC 221: Computer Programming I. Fall 2011 CSC 221: Computer Programming I Fall 2011 Python control statements operator precedence importing modules random, math conditional execution: if, if-else, if-elif-else counter-driven repetition: for conditional

More information

Solution for Homework 2

Solution for Homework 2 Solution for Homework 2 Problem 1 a. What is the minimum number of bits that are required to uniquely represent the characters of English alphabet? (Consider upper case characters alone) The number of

More information

Analysis of Binary Search algorithm and Selection Sort algorithm

Analysis of Binary Search algorithm and Selection Sort algorithm Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

12-6 Write a recursive definition of a valid Java identifier (see chapter 2).

12-6 Write a recursive definition of a valid Java identifier (see chapter 2). CHAPTER 12 Recursion Recursion is a powerful programming technique that is often difficult for students to understand. The challenge is explaining recursion in a way that is already natural to the student.

More information

The While Loop. Objectives. Textbook. WHILE Loops

The While Loop. Objectives. Textbook. WHILE Loops Objectives The While Loop 1E3 Topic 6 To recognise when a WHILE loop is needed. To be able to predict what a given WHILE loop will do. To be able to write a correct WHILE loop. To be able to use a WHILE

More information

JavaScript and Dreamweaver Examples

JavaScript and Dreamweaver Examples JavaScript and Dreamweaver Examples CSC 103 October 15, 2007 Overview The World is Flat discussion JavaScript Examples Using Dreamweaver HTML in Dreamweaver JavaScript Homework 3 (due Friday) 1 JavaScript

More information

Appendix A Doing Things in R

Appendix A Doing Things in R 271 Appendix A Doing Things in R This appendix is not an exhaustive list of all the things that R can do, but rather a list of some common steps you may want to take gathered in one convenient place, and

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 5 Lecture 5-3: Boolean Logic and Assertions reading: 5.3 5.5 1 2 Type boolean boolean: A logical type whose values are true and false. A logical test is actually a boolean

More information

Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor

Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor Created by Simon Monk Last updated on 2014-04-17 09:00:29 PM EDT Guide Contents Guide Contents Overview Parts Part Qty PWM The PWM Kernel Module

More information

Chapter 6: Episode discovery process

Chapter 6: Episode discovery process Chapter 6: Episode discovery process Algorithmic Methods of Data Mining, Fall 2005, Chapter 6: Episode discovery process 1 6. Episode discovery process The knowledge discovery process KDD process of analyzing

More information

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits: - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed Drawbacks: - Hard to search in less than O(n) time (binary

More information

for while ' while ' for * for <var> in <sequence>: <body> $ %%" 0 *0

for while ' while ' for * for <var> in <sequence>: <body> $ %% 0 *0 # & for while while # * # & *, /01* for * 2 for in : ,var 0 2, /01* *** 0 *0 *& 4 00 *0* * /01* 4 6, 4 * /01* Input the count of the numbers, n Initialize sum to 0 Loop n times Input

More information