REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Programming Languages: Notes for Class Discussion: V Deena Engel’s class.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Chapter 2: Input, Processing, and Output
The If/Else Statement, Boolean Flags, and Menus Page 180
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Variables in Java Part 2. ICS-3M1 - Mr. Martens - Variables Part 2 Recall the “int” Data Types When you divide one integer by another – you always get.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Input, Output, and Processing
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
ITBP 119 Algorithms and Problem Solving Section 2.1 Installing software Section 2.2 First Programs Section 2.3 Variables.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
CPS120: Introduction to Computer Science Operations Lecture 9.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Chapter 5: More on the Selection Structure
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
22/11/ Selection If selection construct.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
Decision Structures, String Comparison, Nested Structures
Cosc175/operators1 Algorithms computer as the tool process – algorithm –Arithmetic: addition,subtraction,multiplication,division –Save information for.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Logical Operators, Boolean Variables, Random Numbers This template was just too good to let go in one day!
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
Python Let’s get started!.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Testing.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Variables, Types, Operations on Numbers CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Loops, Part II IT108 George Mason University. Indefinite Loop Don’t always have access to the number of iterations ahead of time If a condition (user-response,
Input, Output and Variables GCSE Computer Science – Python.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
Few More Math Operators
Chapter 2 Basic Computation
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Introduction to Python
CMSC201 Computer Science I for Majors Lecture 03 – Operators
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Conditions and Ifs BIS1523 – Lecture 8.
Outline Altering flow of control Boolean expressions
Lesson 04: Conditionals Class Chat: Attendance: Participation
Decision Structures, String Comparison, Nested Structures
int [] scores = new int [10];
If selection construct
Selection Statements.
Core Objects, Variables, Input, and Output
Algorithms computer as the tool process – algorithm
Boolean Expressions to Make Comparisons
Learning Intention I will learn about the different types of programming errors.
Review of Previous Lesson
Presentation transcript:

REVIEW No curveballs this time …

PROBLEM TYPE #1: EVALUATIONS

Evaluate ExpressionOutputData Type 5 – 2 5 ** 2 “5” + “2” “5” * 2 5 / 2 5 // 2 5 % * 2.0

Evaluate ExpressionOutputData Type 5 – 23integer 5 ** 225integer “5” + “2”52string “5” * 255string 5 / 22.5float 5 // 22integer 5 % 21integer float 5.0 * float

Evaluate ExpressionOutputData Type 10 > 2 2 < 1 2 != 4 4 == 2 ** 2 ‘cat’ < ‘dog’ ‘cat’ < ‘Dog’ 5 > 2 and 10 > 11 5 > 2 or 10 > 11 5 > 2 and not (10 > 11)

Evaluate ExpressionOutputData Type 10 > 2TrueBoolean 2 < 1FalseBoolean 2 != 4TrueBoolean 4 == 2 ** 2TrueBoolean ‘cat’ < ‘dog’TrueBoolean ‘cat’ < ‘Dog’FalseBoolean 5 > 2 and 10 > 11FalseBoolean 5 > 2 or 10 > 11TrueBoolean 5 > 2 and not (10 > 11)TrueBoolean

Evaluate ExpressionOutputData Type str.lower(“HeLLo”) str.upper(‘HeLLo’) format(5.1, ‘.2f’) format(5.1, ‘10.2f’) format(5, ‘10d’) random.randint(1,5) len(‘cat’) len(‘cat’ + ‘dog’) not (5 > 2 and 5 < 4 )

Evaluate ExpressionOutputData Type str.lower(“HeLLo”)hellostring str.upper(‘HeLLo’)HELLOstring format(5.1, ‘.2f’)5.10string format(5.1, ‘10.2f’) 5.10string format(5, ‘10d’) 5string random.randint(1,5){1, 2, 3, 4, 5}integer len(‘cat’)3integer len(‘cat’ + ‘dog’)6integer not (5 > 2 and 5 < 4 )TrueBoolean

PROBLEM TYPE #2: SHORT ANSWER

Short Answer – Sample Question ◦ Explain what a Boolean expression is and why you would use one while programming. Give an example in a short code.

Short Answer – Sample Question ◦ Explain what a Boolean expression is and why you would use one while programming. Give an example in a short code. Boolean expressions are conditional statements that compare two or more different values, using an operator (and, or, not, >, =, <=, ==) These expressions always hold a value of either True or False They are normally seen as the conditions of an “IF” statement

Short Answer – Sample Question ◦ Identify two different functions that convert one data type to another. Then use each in an example code and explain when you would use it in an actual program.

Short Answer – Sample Question ◦ Identify two different functions that convert one data type to another. Then use each in an example code and explain when you would use it in an actual program. str(argument) – converts any data type into a string literal int(argument) – converts an argument into an integer, but it must be given that it CAN be converted into an integer, (strings will cauase an error), for floats, it will always round the number down float(argument) – converts an argument into a float, given that the argument CAN be converted into a float

Short Answer – Sample Question ◦ Explain how the “and” and “or” operators work. Write a short code to show an example of each and describe how you would use it in an actual program.

Short Answer – Sample Question ◦ Explain how the “and” and “or” operators work. Write a short code to show an example of each and describe how you would use it in an actual program. The “and” operator checks for two conditions simultaneously and both conditions must hold True in order for the Boolean expression to hold True. The “or” operator checks for two conditions as well, but only one of them needs to hold True in order for the expression to hold True. It can be though of as checking one of two conditions.

Short Answer – Sample Question ◦ What’s the difference between using an “ELIF” statement and a nested decision structure? Describe both individually and explain the difference between them.

Short Answer – Sample Question ◦ What’s the difference between using an “ELIF” statement and a nested decision structure? Describe both individually and explain the difference between them. An ELIF statement is in essence the same thing as a nested decision structure. All ELIF statements can be written using a nested structure, ELIF’s are purely for convenience. However, they are very convenient because an ELIF statement extends a single decision structure while, any time an IF statement is written, you create a new decision structure, whether nested or not.

PROBLEM TYPE #3: TRACE THE OUTPUT

Trace the Output #1

Trace the Output #2

Trace the Output #3

Trace the Output #4 …(1of 3) This problem was made by a fellow student. I figured I would include it here because it serves as good practice. This is only the beginning … see next slide for continuation.

Trace the Output #4 …(2 of 3)

Trace the Output #4 …(3 of 3)

PROBLEM TYPE #4: DEBUGGING

Types of Errors ◦ Syntax errors: the code does not follow the rules for the language; for example, a single quote is used where a double quote is needed, or a colon is missing, or a keyword is used as a variable name print ( “ Hello, world! ’ )

Types of Errors ◦ Runtime errors: in this case, your code is fine but the program does not run as expected (it “crashes”). For example, if your program is meant to divide two numbers, but the divisor is zero, a runtime error will occur. var1 = float( input (‘give me a number:’) ) number = var1 + 4 >> give me a number: seventeen thirty eight # runtime error

Types of Errors ◦ Logic errors: these can be the hardest to find. In this case, the program is correct from a syntax perspective, and it runs, but the result is not what you were looking for. For example, if your program prints “2 + 2 = 5” the answer is … clearly wrong. var = 3.49 print (var) >>

Types of Errors ◦ Please pay close attention this time around to naming the type of error that is being made ◦ Realize the most common error is a syntax error, at least when looking at the source code Example: x = 3 print(x + “4”) # this is considered a syntax error because you # are trying to add an integer to a string

PROBLEM TYPE #5: WRITE A PROGRAM

Write a program that … ◦ Asks the user for two random words. ◦ Sort the words in alphabetical order and print them out. ◦ Sort the words in size order and print them out.

Write a program that …

◦ Has the computer virtually roll two 6-sided dice. ◦ Output the result as follows: Virtual Dice Roll: 3 and 5

Write a program that …

◦ Allows the user to qualify for a credit card. Requirements: -They must make at least $30,000 a year (disregard tax/deductions) -Their rent payment cannot be more than 50% of their total monthly salary -However, if they own their house, you do not need to take their monthly rent into account

Credit Card Qualifier: Sample Runs Credit Card Qualifier Annual Income: Do you own your house? (y/n): y You qualify! Credit Card Qualifier Annual Income: Do you own your house? (y/n): n Monthly Rent: 1200 You qualify! Credit Card Qualifier Annual Income: Do you own your house? (y/n): n Monthly Rent: 4000 Sorry, you do not qualify!

Write a program that …

◦ Allows a user to input the price of 3 items they are purchasing in a store ◦ Then, calculate and print out the subtotal ◦ Calculate the tax (assume 7%) ◦ Finally, print out the total bill ◦ You should format your numbers for money-talk

Write a program that …

◦ Allows a user to type in a 3 digit integer (assume, that the last digit will not be zero) ◦ Print out the original number ◦ Then, print out the number in reversed order Please enter a three digit number: 347 You entered: backwards is 743

Write a program that …

◦ Asks the user to type in a 2 digit integer (assume, that the last digit will not be zero), and call it variable x ◦ Then, figure out variable y, which is number with the same digits as x but reversed order ◦ Then, print out x and y and their sum Please enter a two digit number: reversed is is 77

Write a program that …

BEST OF LUCK!