CISC101 Reminders All assignments are now posted.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to Python
Introduction to C Programming
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
Input & Output: Console
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
The Java Programming Language
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.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Python Functions.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
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.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
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
C++ First Steps.
Last Time Unary operators: Other Assignment operators
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
Introduction to Python
Variables and Primative Types
Variables, Expressions, and IO
Functions CIS 40 – Introduction to Programming in Python
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.
2.1 Parts of a C++ Program.
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Winter 2018 CISC101 11/27/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
Winter 2018 CISC101 12/1/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.
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:
Topics Introduction to Functions Defining and Calling a Void Function
CISC124 Labs start this week in JEFF 155.
CISC124 Labs start this week in JEFF 155. Fall 2018
Chapter 2: Introduction to C++.
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
COMPUTER PROGRAMMING SKILLS
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due today.
CMPE212 – Reminders Assignment 2 due next Friday.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

CISC101 Reminders All assignments are now posted. Winter 2019 CISC101 4/27/2019 CISC101 Reminders All assignments are now posted. Assignment 1 due this Friday. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Today Comparing Strings. Winter 2019 CISC101 4/27/2019 Today Comparing Strings. Continue Coding Style (also applicable to your Assignment 1 code). What is a Function? What is a Method? Start a review of Input/Output functions and methods. Winter 2019 CISC101 - Prof. McLeod Prof. Alan 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 2019 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 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

ASCII Table (Lower Half) Winter 2019 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 2019 CISC101 - Prof. McLeod

Coding Style, So Far… Yesterday’s video discussed: Commenting Code. Documentation Strings. Being Careful with Indentation. Use of Whitespace – blank lines and spaces. Winter 2019 CISC101 - Prof. McLeod

Coding Style: Misc. No code after a : when it is used with a def, if or while loop. Define main at the top of your program or at the end - not in the middle! One import statement per line. Put import statements before globals but after block comments and module-level doc strings. (There is a big set of additional rules for doc strings themselves that I won’t get into here…) Winter 2019 CISC101 - Prof. McLeod

Do # This program is used to demonstrate better style. # Version 1, by Alan McLeod, 27 Oct. 2011 def product(num1, num2) : '''This is a useless little function that does not do much''' print('Hello') return num1 * num2 def main() : '''main invokes product and then waves goodbye!''' print(product(3, 4)) print('Goodbye!') main() Winter 2019 CISC101 - Prof. McLeod

Don’t! This works! How many things are wrong with this code? def m(ll1,l1):print('Hello');return(ll1*l1); def main():print(m(3,4));print("Goodbye!") main () This works! How many things are wrong with this code? Winter 2019 CISC101 - Prof. McLeod

Python Style Guides From Google: http://google.github.io/styleguide/pyguide.html Lots of detail – more than you need, right now. Originally intended for internal use (Google uses Python a lot – or at least, they used to…). At python.org, “PEP 8”: http://legacy.python.org/dev/peps/pep-0008/ Winter 2019 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 2019 CISC101 - Prof. McLeod

Variable and Function Names, Cont. Be descriptive, but not excessive! Examples: numStudents setPassingGrade ( parameter list ) Somewhat too long…: flagThatIsSetToTrueIfAProblemArisesWhenThereIsAFullMoonOverMyHouseInTheWinterWhileMyProgramIsRunning Winter 2019 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 2019 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 2019 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 2019 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 2019 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 2019 CISC101 - Prof. McLeod

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

Functions and Methods What’s the difference? 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 2019 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 2019 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). A function has a limited and defined interface to a program that uses the function. Winter 2019 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 2019 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 2019 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 2019 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 2019 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 2019 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 2019 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 2019 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 2019 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 2019 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 2019 CISC101 - Prof. McLeod