Spring 2015.  Problems:  Mandelbrot set  Time Travel Securities, Inc.  Pi from pie  Extra Credits:  Sequence Sums.

Slides:



Advertisements
Similar presentations
What type of data can a variable hold?
Advertisements

The Random Class.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Logic & program control part 3: Compound selection structures.
HW 4 EECS 110.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
Example – calculating interest until the amount doubles using a for loop: will calculate up to 1000 years, if necessary if condition decides when to terminate.
Efficiency of Algorithms
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
HW 1: Problems 3 & 4 EC 1 & 2.
Intro to Robots Conditionals and Recursion. Intro to Robots Modulus Two integer division operators - / and %. When dividing an integer by an integer we.
Java Coding 3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Over & over again!
Unit 5 while loops; logic; random numbers; tuples Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work.
Programming for Linguists An Introduction to Python 24/11/2011.
General Programming Introduction to Computing Science and Programming I.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
PHP flow of control & functions
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Additional Problems.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
This week in CS 5 HW 9 (2 problems) M/T sections W/Th sections due Sunday, 11/4 at midnight due Monday, 11/5 at midnight Recitation for HW9 -- Friday 11/2.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Input and typing trouble! print 'Please input a number of meters' meters = input() # get input from user cm = meters * 100 # convert to centimeters print.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
1 Chapter 4: Basic Control Flow ► Chapter Goals  To be able to implement decisions using if statements  To understand statement blocks  To learn how.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Exercise 2 Introduction to C# CIS Create a class called Employee that contains the following private instance variables: Social Securitystring.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Homework 8 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/28 Mon., 10/29 Problems Reading is under week 7, however.
EECS 110: Lec 10: Definite Loops and User Input Aleksandar Kuzmanovic Northwestern University
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 10 Lists 1.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 2 Karsten Hokamp, PhD Genetics TCD, 17/11/2015.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Tutorial 9 Iteration. Reminder Assignment 8 is due Wednesday.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
C# Programming Methods.
Useful Python CMSC 120: Visualizing Information. Scope def area(diameter): radius = diameter / 2.0 A = PI * radius ** 2 return A def circumference(diameter):
Introduction to Python Developed by Dutch programmer Guido van Rossum Named after Monty Python Open source development project Simple, readable language.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
2.4 Measures of Variation The Range of a data set is simply: Range = (Max. entry) – (Min. entry)
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Input, Output and Variables GCSE Computer Science – Python.
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
Python Basics.
EECS 110: Lec 10: Definite Loops and User Input
Python unit_4 review Tue/Wed, Dec 1-2
Engineering Innovation Center
LOOPS.
EECS 110: Lec 10: Definite Loops and User Input
Python I/O.
Do While (condition is true) … Loop
Coding Concepts (Basics)
Spring 2010 EECS 110: Homework I.
Let A = {image} and B = {image} . Compare A and B.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
§ § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § § ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
Algorithmic complexity: Speed of algorithms
EECE.2160 ECE Application Programming
Spring 2018 EECS 110: Homework IV.
Question 1a) What is printed by the following Java program? int s;
Presentation transcript:

Spring 2015

 Problems:  Mandelbrot set  Time Travel Securities, Inc.  Pi from pie  Extra Credits:  Sequence Sums

 The correct result:

 Function tts() prints a menu (0) Input a new list (1) Print the current list (2) Find the average price (3) Find the standard deviation (4) Find the min and its day (5) Find the max and its day (6) Your TT investment plan (9) Quit Enter your choice:

 Take user’s choice  Can be integer or a string  Print warning if choice is not valid  9 : Quit  0 : Take input as a list  Ex: [20,10,30]  Start with an empty list  New list will be appended to the current  Change the type of input() if necessary!

 1 : Print out the current list  For each entry, print out the index and the value  Ex: Day | Price | | |  2, 4, 5 : Straight-forward

 3 : Find Standard Deviation  List L has average Lav  Standard deviation is sqrt((sum(L[i]-Lav)**2)/len(L))  6 : Find the best buy day and sell day  To maximize profit (note: buy day < sell day)  Comments:  Add new options for extra credit (up to 10 pts)  Should have a helper function for each option

def tts(): quit = False while... # quit is not True # print menu... # get user input... # if input is 9, quit = True # else print out the answer...

 Idea: π = Area of the circle inscribed a 2 by 2 square  Estimating π using random dart-throwing  A square from (-1,-1) to (1,1) 1 1 Area of Circle = Number of darts hit the circle Area of Square Total number of darts

 Take input n as a positive integer  Sequentially throw n darts into the square:  Each throw = randomly choose a point  A point has coordinate (x,y) between -1 and 1  Determine if (x,y) is in the circle  After each throw:  Print out number of darts thrown so far  Number of darts hit the circle  The current estimate of π

def forPi(n): # initiate variables... for i in... # pick (x,y) randomly... # if (x,y) is in the circle # update the number of hits # print out things...

 Take input error as a positive floating point  Throw darts until the estimate error < error  Estimate error = |estimate π – actual π|  After each throw print as in forPi(n)

def whilePi(error): # initiate variables... while # estimate error > error # pick (x,y) randomly... # if (x,y) is in the circle # update the number of hits # update the estimation # print out things...

 Choosing random number random.uniform(-1.0,1.0)  Distance between (x,y) and (0,0) : sqrt(x**2+y**2)

 Look and Say  Harmonic series  Harmonic series without d (Kempner series)

 Look and Say sequence: 1, 11, 21, 1211, , , ,…  readOne(s) returns the reading of string s :  Examples: readOne('11') returns '21' readOne('312211') returns ' '  Should use both recursion and loop  Base case: len(s) == 1 '

 Weep(n) generates the first n terms: Example: Weep(8) prints '

 Harmonic series is 1 + 1/2 + 1/3 + 1/4 + 1/5 + …  Divergence (very slow)  harmonicN(numToReach) returns the smallest number of terms required to exceed numToReach '

 Harmonic series without digit d: remove all term that has digit d in the denominator  Example, d = 2: remove the following terms: 1/2, 1/12, 1/20, 1/21,…, 1/32, 1/42,…  Convergence (very slow)  Withoutd(d,Numterms) returns the Harmonic series without d, calculated using exactly Numterms terms '

 Python may lose precision  Use package decimal :  Preamble: from decimal import * getcontext().prec = 20  Turn number to Decimal format Decimal(n)  Operations stay the same  Turn Decimal format to string: str(x) '

Have fun + Good luck