Winter 2018 CISC101 12/1/2018 CISC101 Reminders

Slides:



Advertisements
Similar presentations
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Advertisements

Introduction to C Programming
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Introduction to Python
Input & Output: Console
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Input, Output, and Processing
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
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.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Python Let’s get started!.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Managers and “mentors” identified on projects page. All member accounts created and projects populated.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Today… Style, Cont. – Naming Things! Methods and Functions Aside - Python Help System Punctuation Winter 2016CISC101 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. Winter 2016CISC101 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Bill Tucker Austin Community College COSC 1315
CS 106A, Lecture 4 Introduction to Java
C++ First Steps.
Definition of the Programming Language CPRL
Chapter 2 Variables.
Python Let’s get started!.
Introduction to Python
Variables and Primative Types
Variables, Expressions, and IO
Java Programming: From Problem Analysis to Program Design, 4e
Winter 2018 CISC101 11/9/2018 CISC101 Reminders
CISC101 Reminders Quiz 2 this week.
CISC101 Reminders Assn 3 due Friday, this week.
Winter 2018 CISC101 11/16/2018 CISC101 Reminders
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Introduction to C++ Programming
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CISC101 Reminders Slides have changed from those posted last night…
Winter 2018 CISC101 11/27/2018 CISC101 Reminders
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Chapter 2 Variables.
T. Jumana Abu Shmais – AOU - Riyadh
Fall 2018 CISC124 2/15/2019 CISC124 TA names and s will be added to the course web site by the end of the week. Labs start next week in JEFF 155:
CISC124 Labs start this week in JEFF 155.
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
CISC124 Labs start this week in JEFF 155. Fall 2018
Winter 2019 CISC101 4/8/2019 CISC101 Reminders
CISC101 Reminders All assignments are now posted.
Winter 2019 CMPE212 4/7/2019 CMPE212 – Reminders
CISC101 Reminders Assignment 2 due today.
Fundamental Programming
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Winter 2019 CISC101 4/14/2019 CISC101 Reminders
CISC101 Reminders Quiz 1 marking underway.
CISC101 Reminders All assignments are now posted.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Unit 3: Variables in Java
Chapter 2 Variables.
CISC101 Reminders Assignment 3 due today.
Presentation transcript:

Winter 2018 CISC101 12/1/2018 CISC101 Reminders The Prof will mark Quiz 1. Marks will be released and you can view your graded quiz once they are all marked. Assn 1 now due Monday, Feb. 5, next week. Exercise 3 is fair game now – conditionals. Videos are all caught up now. All assignments are posted from the course web site. Winter 2018 CISC101 - Prof. McLeod Prof. Alan McLeod

Today Error in Jan. 25 Slides on Precedence. Aside on Comparing Strings More Style – Naming “Things” Back to Building Expressions: Invoking Functions. (sneak in a bit of a discussion of Console I/O) Punctuation Keywords (next time…) Winter 2018 CISC101 - Prof. McLeod

Precedence Rule Error in Jan. 25 Slides (My thanks to the student that pointed this out!) Slide 25 says that unary operators (not and negation) come before **, which contradicts what it says on slide 14, which has ** before unary negation. Slide 14 is correct, slide 25 is in error. You can confirm this by evaluating an expression like: -5 ** 2 at the Python prompt. The answer will be -25, which means that the negation takes place after the **. The rest of slide 25 is OK. Winter 2018 CISC101 - Prof. McLeod

Aside - Comparing Strings Binary Boolean operators work with either numbers on both sides or strings on both sides. But, how are strings compared? Winter 2018 CISC101 - Prof. McLeod

Comparing Strings, Cont. Winter 2013 CISC101 Comparing Strings, Cont. Some examples: "abc" == "abC" gives False "abc" < "abcd" gives True "A" < "a" gives True "a" < "b" gives True "aaa" < "aaaa" gives True These comparisons are based on the ASCII code values of the characters compared. “American Standard Code for Information Interchange” Winter 2018 CISC101 - Prof. McLeod Prof. Alan McLeod

ASCII Table (Lower Half) Winter 2018 CISC101 - Prof. McLeod

Comparing Strings, Summary So, you are still actually comparing numeric values, character by character. A shorter string is less than an otherwise identical longer string. Capitals are less than lower case letters. This is important when sorting or analyzing textual information. Winter 2018 CISC101 - Prof. McLeod

Variable and Function Names Follow Python restrictions on names: Use only letters, numeric digits (0 to 9) and the “_” character. Cannot start name with a number. Python is case sensitive! Variables and function names usually start with a lower case character. Class names start with an upper case character. Constants are all in upper case. The use of one or two underscores and the beginning and/or the end of a variable name has a special meaning in Python… Variables are usually nouns. Functions are verbs or verbs and nouns. Winter 2018 CISC101 - Prof. McLeod

Variable and Function Names, Cont. Be descriptive, but not excessive! Examples: numStudents setPassingGrade ( parameter list ) Somewhat too long…: flagThatIsSetToTrueIfAProblemArisesWhenThereIsAFullMoonOverMyHouseInTheWinterWhileMyProgramIsRunning Winter 2018 CISC101 - Prof. McLeod

Variable and Function Names, Cont. Use camelCase for variable names (Google Python Style Guide says use underscores – I don’t like that style in Python, personally). Note that Python keywords are in all lower case. You will get an error message if you attempt to use a keyword as a variable name. It is very tacky to use a keyword as a variable name, just by changing the capitalization! Winter 2018 CISC101 - Prof. McLeod

Naming Variables Also applies to naming parameters, functions, methods and classes. The name should reveal the intention of what it is you are naming. You should not need to add a comment to a variable declaration to provide further explanation. A comment is OK if you want to record the units of the variable or if you need to explain the initial value. Winter 2018 CISC101 - Prof. McLeod

Naming Variables, Cont. Avoid Disinformation Avoid using words that might have multiple meanings. Make Meaningful Distinctions Don’t use artificial means of distinguishing similar names. Examples: account0 or account1, accountNum or accountNums Winter 2018 CISC101 - Prof. McLeod

Naming Variables, Cont. Use Pronounceable Names It is easier for our brains to remember a variable name if it is pronounceable. Use Searchable Names For example, single or even two-letter variable names will be difficult to locate using a text search. If a loop counter has no intrinsic meaning then it is OK to use i, j and k (but not l !!!) as loop counters. Winter 2018 CISC101 - Prof. McLeod

Naming Variables, Cont. Avoid Encodings Older naming conventions might use a prefix or suffix to indicate the type or membership of a variable – this is no longer necessary. Use One Word per Concept For example don’t use all of the terms “manager”, “controller” and “driver” – what is the difference? Winter 2018 CISC101 - Prof. McLeod

Coding Style - Above All Else: Be Consistent! Winter 2018 CISC101 - Prof. McLeod

Aside - Functions and Methods A reminder: A method belongs to an object and must be invoked from an instance of that object (see the .format() method in Exercise 2, for example). A function stands alone and does not belong to any object. We can define our own functions or invoke functions that have already been defined for us. Winter 2018 CISC101 - Prof. McLeod

Functions What is a “Function”? This is a collection of lines of code that are contained in a function definition. A function should perform a single specific task. You can run these lines of code by invoking the function. We have been adding code to a function called “main”. Winter 2018 CISC101 - Prof. McLeod

Functions, Cont. A function is characterized by: Its name. The use of round brackets () after the name. Its parameter list inside the round brackets (none, one or many parameters!) Its return value (none or one thing, but that one thing could be a collection). Winter 2018 CISC101 - Prof. McLeod

Aside - Invoking Functions How do you invoke a function? You name the function and then must supply a set of brackets ( ). The brackets could be empty or might contain one or more arguments. Arguments are mapped to parameters inside the function. Parameters act like variables inside the function. Functions we have already seen and used: print(), input(), int(), bin(), hex(), type(). Winter 2018 CISC101 - Prof. McLeod

Using BIFs and Methods, Ex: Console I/O Or “Input/Output” How you interact with the “user” of your program. Use two BIFs – print() for Output and input() for Input. Control output format using escape sequences, the .format() method or “formatted” strings that have the “f” in front of them. Winter 2018 CISC101 - Prof. McLeod

Console (or Screen) Input CISC101 Console (or Screen) Input Use the input() function, which returns a string (even if you type in a number). Supply a prompting string to the input() function as a parameter. The function returns what the user has typed in. (How do you get a number from the input() function’s returned string?) Winter 2018 CISC101 - Prof. McLeod Prof. Alan McLeod

Using the print() BIF You can supply any number of parameters to the function, including no parameters at all, by supplying a comma-separated list of parameters inside the brackets. Parameters can be variables or literal values (or values supplied by some other function). Comma separated values are printed together on the same line, separated by a space, by default. Winter 2018 CISC101 - Prof. McLeod

Escape Characters Can be used to control how strings are displayed when using the print() function. See the Python Help docs, as well: \n - linefeed \t – tab character \’ – single quote \” – double quote \\ - backslash (You can also use triple quotes to create a multi-line string without using escape characters…) Winter 2018 CISC101 - Prof. McLeod

Modifying How print() Works There are two keyword parameters that affect: what goes between multiple arguments, and how the printed line is terminated. The first is sep=, where the default is sep=" " The second is end=, where the default is end="\n" For example: print("Hello", "world", sep="***", end="!\n") Displays: Hello***world! Winter 2018 CISC101 - Prof. McLeod

More Output Formatting The str.format() method gives you complete control over how information is displayed in the console window. Here is an example from Exercise 2: >>> print("The variable a is: {0}, b is: {1} and c is: {2}.".format(a, b, c)) The variable a is: 123, b is: 45678 and c is: 21. Get more info from Exercise 2. Winter 2018 CISC101 - Prof. McLeod

Aside – .format() Method .format() is like a function, but it is invoked differently. .format() is a member function of the string (or str) object. So, you must have a string object in order to invoke this method or “member function”. Don’t worry too much about this, for now… Winter 2018 CISC101 - Prof. McLeod

Formatted Strings in New Python Versions This is even easier: print(f"The variable a is: {a}, b is: {b} and c is: {c}.") You can use formatting codes for each variable if you put them after a colon (:) inside the { }. Winter 2018 CISC101 - Prof. McLeod

Aside – the round BIF You can use the round BIF to round numbers to a certain number of digits before you display them. For example: >>> aNum = 15.45789 >>> print("Rounded is", str(round(aNum, 2))) Rounded is 15.46 The first argument to round() is the number to be rounded, the second argument is the number of digits you want to have after the decimal place. Winter 2018 CISC101 - Prof. McLeod