CS 101 – Oct. 15 Common elements in solutions –Types of variables –Traversing values in a list –Assigning vs. checking if equal –Printing things on the.

Slides:



Advertisements
Similar presentations
Computer Science 101 While Statement. Iteration: The While-Statement The syntax for the While- Statement is while : The syntax for the While- Statement.
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
While Loops. Challenge: ● Ask the user a simple math questions ● Continue asking the question until the user gets it right.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
Computer Science 1620 Programming & Problem Solving.
Chapter 1 Pseudocode & Flowcharts
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
From Scratch to Python Learn to program like the big boys / girls!
Warm Up Write an algebraic expression for 35 less than product of 4 and x. A35 + 4x B4x - 35 C35 / 4x D35 – 4x.
Microsoft® Small Basic
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
An Overview of Programming in Python CSC 161: The Art of Programming Prof. Henry Kautz 9/9/2009 Slides stolen shamelessly from Dr. Mark Goadrich, Centenary.
Variables and Equations Pre-Algebra. Learning Objective I can solve equations with variables.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Computer Science 101 Introduction to Programming.
By the end of this session you should be able to...
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
Lesson 6-3B Objective: Solve inequalities using more than one step…continued.
CHAPTER 5 TEST REVIEW SHOW ME THE MONEY!. QUESTION #1 Find the perimeter and area of the figure. 18ft 36ft 18ft 9ft A. 324ft², 72ft B. 162ft², 72ft C.
Solving systems of equations with 2 variables
How to start Visual Studio 2008 or 2010 (command-line program)
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Greatest Integer/Absolute Value Functions
Writing & Solving Equations
INTEGERS – Product & Quotient. Multiplying Integers - remember our changing sign table ? + + changes to changes to changes to changes.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Solve the following word problem. Manny is two years older Enrique. The sum of the their ages is 40. How old is Manny and Enrique? Let: m = Manny’s age.
Bellwork Unit 1 Quiz Sept 2015 Simplify each expression #1-5. Write the problem and answer. 1: -½ ( ¼ x + 10) 2: 8y – 2x + y + 5y 3: 9ab + 3a.
Computer Science 1000 Algorithms III. Multiple Inputs suppose I ask you to write a program that computes the area of a rectangle area = length * width.
Solving and Graphing Inequalities CHAPTER 6 REVIEW.
Do Now Look at each pattern or conjecture and determine whether each conjecture is valid. 1.2, 6, 14, 30, 62, 126 Conjecture: Each element is two more.
Solving One-Step Inequalities
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Identities, Contradictions and Conditional Equations.
Lesson Days Equations and Problem Solving Pages
Input, Output and Variables GCSE Computer Science – Python.
ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.
FIND THE VOLUME: 5 in 8 in 4 in.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Warm-up October 14, ) Write an algebraic expression for the area AND perimeter of the rectangle. 8 x + 6 Make sure to simplify both expressions.
Selection and Python Syntax
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Starter Write a program that asks the user if it is raining today.
3 Solving Application Problems.
G7 programing language Teacher / Shamsa Hassan Alhassouni.
Introduction to Python
Use the substitution method to find all solutions of the system of equations {image} Choose the answer from the following: (10, 2) (2, 10) (5, - 2) ( -
Chapter 2 Review Chapter 2 Test tomorrow!!!!!.
3.4 - Solving Variables on Both Sides
Solving Linear Equations Unit Test Review Game
Lesson Objective: I will be able to …
Exercise 2x − 3 = 9 x = 6.
Inputs and Variables Programming Guides.
Find the reference angle for the angle measuring {image}
SECTION 2-4 : SOLVING EQUATIONS WITH THE VARIABLE ON BOTH SIDES
Python Basics with Jupyter Notebook
Relational Operators.
one of the equations for one of its variables Example: -x + y = 1
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.
CS 1111 Introduction to Programming Spring 2019
Class code for pythonroom.com cchsp2cs
Area = l(w) 38 = 2(3x + 4) 38 = 6x = 6x = x CHECK: 38 = 2(3(5) + 4) 38 = 2(15 + 4) 38 = 2(19) 38 = 38 √
Lec 21 More Fun with Arrays: For Loops
True or False True or False
COMPUTING.
H446 Computer Science.
Introduction to Python
Presentation transcript:

CS 101 – Oct. 15 Common elements in solutions –Types of variables –Traversing values in a list –Assigning vs. checking if equal –Printing things on the same line Examples and practice

Variables Python loves variables. And Python understands that a variable can be used for different purposes: –Number (both integer and real)radius = 2.5 –Textname = “Martha” –True or Falseleap = True Caution: if you want to divide two numbers, you should use real numbers. For example, one-third should be 1.0/3.0 because 1/3 is dividing integers, which equals 0.

Traversing a list We want to visit each element. Two ways to do this: L = [ 5, 4, 7, 3, 2, 6, 1] for number in L: print L for i in range (0, 7): print L[i]

= versus == In Python (and other languages), we need to distinguish between: –Assigning a value to a variable: x = 5 –Asking if two quantities are equalx == 5 For example, if hours == 40: overtime = False

Output The “print” statement is designed to display a line of text, and then go on to the next line. Sometimes we want to continue output on the same line. Two approaches –Put comma at end of statementprint “$ ”, – Tell Python you want to print several things. However, if you are printing both text and numbers, you need to put str( ) around the number. –See list.py example.

Examples Ask the user for the length and width of a rectangle. Output the area and perimeter. Ask the user what 7+5 is. Tell user if the answer is correct or not. Count how many numbers in a list equal 5.

Rectangle # rectangle.py # Find area and perimeter of user’s rectangle. length = input(“What is the length?”) width = input(“What is the width?”) area = length * width perimeter = 2 * (length + width) print "The area is " + str(area) print "The perimeter is " + str(perimeter)

User Quiz # quiz.py # See if the user knows what 7+5 is. answer = input(“What is 7 plus 5?”) if answer == 12: print "Good job!" else: print "Sorry, that’s not correct."

Count the 5’s # count5.py # Count the 5’s in a list L = [ 5, 4, 2, 5, 1, 2, 5 ] fives = 0 for number in L: if number == 5: fives = fives + 1 print "I found " + str(fives) + " fives."