Lecture 17 – Practice Exercise 3 SOLUTIONS

Slides:



Advertisements
Similar presentations
Summer 2012 Instructor: Hassan Khosravi
Advertisements

Main task -write me a program
Please open your laptops, log in to the MyMathLab course web site, and open Daily Quiz 16. IMPORTANT NOTE: If you have time left out of your five minutes.
Adapted from slides by Marie desJardins
PYTHON PROGRAMMING Week 10 – Wednesday. TERMS – CHAPTER 1 Write down definitions for these terms:  Computation  Computability  Computing  Artificial.
Homework #4: Operator Overloading and Strings By J. H. Wang May 8, 2012.
Lecture 3.4: Recursive Algorithms CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag.
30/10/ Iteration Loops Do While (condition is true) … Loop.
ALGORITHMS.
Homework #4: Operator Overloading and Strings By J. H. Wang Apr. 17, 2009.
Homework #4: Operator Overloading and Strings By J. H. Wang May 12, 2014.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
Homework #4: Operator Overloading and Strings By J. H. Wang May 22, 2015.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Welcome to CMPT 225 Data Structures and Programming Anne Lavergne
Lecture 3.4: Recursive Algorithms CS 250, Discrete Structures, Fall 2015 Nitesh Saxena Adopted from previous lectures by Zeph Grunschlag.
Starter What does the following code do?
CMPT 120 Topic: Python’s building blocks -> More Statements
Topic: Introduction to Computing Science and Programming + Algorithm
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Functions – Part 1
Applied Discrete Mathematics Week 2: Functions and Sequences
Topic: Iterative Statements – Part 1 -> for loop
Python: Experiencing IDLE, writing simple programs
CMPT 120 Topic: Python Modules.
IST256 : Applications Programming for Information Systems
Topic: Introduction to Computing Science and Programming + Algorithm
Topic: Python’s building blocks -> Statements
Topic: Conditional Statements – Part 1
CMSC201 Computer Science I for Majors Lecture 22 – Searching
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Conditional Statements – Part 2
CMPT 120 Topic:  Case Study.
C++ Basic Syntax – Homework Exercises
CMPT 120 Topic: Functions – Part 4
National 5 Computing Science Specimen Question Paper
Topic: Functions – Part 2
CS 108 Computing Fundamental Notes for Thursday, October 5, 2017
Building Java Programs Chapter 14
CMIS 102 Competitive Success-- snaptutorial.com
CMIS 102 Education for Service-- snaptutorial.com
CMIS 102 Teaching Effectively-- snaptutorial.com
Learning to Program in Python
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Learning to Program in Python
Do While (condition is true) … Loop
Starter answer these questions in your book
What's wrong with Easter jokes? They crack you up
slides created by Marty Stepp
Python Basics with Jupyter Notebook
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
CMPT 120 Lecture 12 – Unit 2 – Cryptography and Encryption –
Topic: Iterative Statements – Part 2 -> for loop
Lecture 7 – Unit 1 – Chatbots Python – For loops + Robustness
CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
CMPT 120 Lecture 9 – Unit 2 – Cryptography and Encryption –
CMPT 120 Lecture 4 – Unit 1 – Chatbots
CMPT 120 Lecture 6 – Unit 1 – Chatbots
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Midterm - 1 Instructions
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
Lecture 17 – Practice Exercises 3
Lecture 20 – Practice Exercises 4
CMPT 120 Lecture 24 – Unit 4 – Computer Vision
Lecture 20 – Practice Exercises 4
Lecture 23 – Practice Exercises 5
Lecture 37 – Practice Exercises 9
Lecture 37 – Practice Exercises 9
Presentation transcript:

Lecture 17 – Practice Exercise 3 SOLUTIONS CMPT 120 Lecture 17 – Practice Exercise 3 SOLUTIONS

Goals for Today! Practise designing a solution (algorithm) to a problem Practise implementing a program (solution) described by an algorithm

Question 1 Homework – from a few lectures’ ago! Problem Statement: Given 3 numbers, find the largest one. How to proceed: Write an algorithm, i.e., steps, in pseudocode (not in Python) on the supplied piece of paper Write your name Submit at the end of the lecture Possible solution: https://repl.it/repls/TeemingMicroHandwritingrecognition

Question 1 – Handout – Page 1 Homework – from a few lectures’ ago! Problem Statement: Given 3 numbers, find the largest one.

Question 2 Problem Statement: How to proceed: Given 2 words, figure out if they are palindromes. How to proceed: Write an algorithm, i.e., steps, in pseudocode (not in Python) on the supplied piece of paper Write your name Submit at the end of the lecture Possible solution : https://repl.it/repls/HoneydewGrouchyMetrics

Question 2 – Handout – Page 2 Problem Statement: Given 2 words, figure out if they are palindromes.

Question 3 – Homework – from a few lectures’ ago! Problem Statement: Let’s create a function that returns the largest number out of 3 numbers Requirements: You cannot use the max( ) built-in function You cannot use the word max to name your function How to proceed: Implement your algorithm in Python using Repl.It No submission required Possible solution: https://repl.it/repls/TeemingMicroHandwritingrecognition

Question 4 – Back to our Guessing Game Remember our Guessing Game program from Lecture 7 (May 22), have a look at its version 4 on our course web site List an input for which this Guessing Game version 4 works just fine! input: three wrong numbers input: two numbers then the correct number List an input for which this Guessing Game version 4 does not work well (its behaviour does not make sense) ! input: the correct number first input: a wrong number then the correct number

Question 4 – Back to our Guessing Game Problem Statement: Fix our Guessing Game version 4 (hence creating version 5) This signifies that when you enter the input you listed in 2. on the previous slide, our Guessing Game version 5 will work just fine! Possible solution: https://repl.it/repls/HeavenlyBusyNet

Question 5 - Loops Let’s convert the following Python code fragment such that it no longer uses a while loop but instead, it uses a for loop: fruit = ["banana", "apple", "plum"] index = 0 while index < len(fruit): print(fruit[index]) index = index + 1 Solution: for index in range(len(fruit)) :   print(fruit[index])

Question 6 - Strange Calculator Problem Statement: Write a program that takes a string as an input, such as “24 + 16”, “30 – 5”, “10 * 4”, 36 / 2”, compute the equation found in the string and output the equation and its result such as 24 + 16 = 40 Requirements: Note that the output, such as 24 + 16 = 40, is no longer made of strings, but they are all integers Your program cannot make use of functions such as eval( ), etc… Please, feel free to send your solution to this question to the instructor for feedback.