Winter 2019 CISC101 4/14/2019 CISC101 Reminders

Slides:



Advertisements
Similar presentations
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Advertisements

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Input, Output, and Processing
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
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.
Winter 2016CISC101 - Prof. McLeod1 Today Numeric representation (or “How does binary and hexadecimal work?”). How can a CPU understand instructions written.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
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.
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:
Whatcha doin'? Aims: To start using Python. To understand loops.
Topics Designing a Program Input, Processing, and Output
Introduction to Python
Building Java Programs
Variables, Expressions, and IO
CISC124 Labs start this week in JEFF 155: Meet your TA.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Winter 2018 CISC101 11/9/2018 CISC101 Reminders
CISC101 Reminders Quiz 2 this week.
CISC101 Reminders Assn 3 due Friday, this week.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
Winter 2018 CISC101 11/15/2018 CISC101 Reminders
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Number and String Operations
Introduction to C++ Programming
CISC101 Reminders Your group name in onQ is your grader’s name.
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CISC101 Reminders Slides have changed from those posted last night…
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 11/27/2018 CISC101 Reminders
Winter 2018 CISC101 11/29/2018 CISC101 Reminders
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Building Java Programs
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
CISC101 Reminders Quiz 2 this week.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
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 Assignment 1 due this Friday, 7pm.
Class 2.
CISC124 Assignment 1 due this Friday, 7pm.
Winter 2019 CISC101 4/8/2019 CISC101 Reminders
CISC101 Reminders All assignments are now posted.
Topics Designing a Program Input, Processing, and Output
CISC101 Reminders Labs start this week. Meet your TA! Get help with:
Winter 2019 CISC101 4/8/2019 CISC101 Reminders
Winter 2019 CMPE212 4/7/2019 CMPE212 – Reminders
CISC101 Reminders Assignment 2 due today.
CMPE212 – Reminders The other four assignments are now posted.
Topics Designing a Program Input, Processing, and Output
Introduction to Primitives
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
Introduction to Primitives
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Beginning Python Programming
CISC101 Reminders Quiz 1 marking underway.
CISC101 Reminders All assignments are now posted.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due today.
Introduction to Python
Presentation transcript:

Winter 2019 CISC101 4/14/2019 CISC101 Reminders You have been assigned to two groups in onQ – the “Lab” group and the “Grader” group. You must write the quiz in the lab time as indicated by the Lab group you are in. “Grader” is the TA who will be grading your assignments. Quiz 1 next week, starting in the Tuesday lab. More info coming up… Exercise 2 is now fair game – this would be good preparation for the coding part of the quiz. Assignment 1 due next Friday. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Quiz 1 Topics Everything up to and including this Friday’s lecture. But not Conditionals. Exercises 1 and 2 are fair game. Emphasis on: Computing background history tidbits. How a computer works. Digital systems logic. Controlling the CPU. Python history and features. Python types, variables, expressions and console I/O. Python coding – simple linear programs. Winter 2019 CISC101 - Prof. McLeod

Quiz 1 Restrictions The quiz will start out showing that it is open only for the Tuesday lab between 11:30 and 1:30pm. When this lab is over the quiz will be re-opened for the Thursday labs. You must write the quiz in the lab time you chose in SOLUS – as indicated by the Lab group you have been assigned to in onQ. If you cannot do so, email the prof with a good reason. The quiz can only be opened in JEFF155 – it is IP address restricted to only the lab machines. Winter 2019 CISC101 - Prof. McLeod

Quiz 1 Format Electronic – in onQ. No aids. About 45 minutes. T/F and short answer. Short answer could be a code segment or possibly a complete program. Code writing will be towards the end of the quiz – leave yourself enough time!!! You will need to be able to write a simple Python program. Winter 2019 CISC101 - Prof. McLeod

Quiz 1 Format, Cont. When typing code directly into a multi-line answer box avoid using the <tab> key. This key will not give you a tabbed space but will just move the cursor out of the box, which is really annoying. Use just the spacebar for spacing, say 3 or 4 spaces per indent. Style is not critical, but nice looking code is easier to read and grade for an old guy like me… Winter 2019 CISC101 - Prof. McLeod

Quiz 1 Rules You will use onQ, but no other programs can be used on any device. No other aids. The TA must be able to see your screen. No talking to other students when writing. If you have written, please keep the noise down until all other students have finished writing the quiz. Winter 2019 CISC101 - Prof. McLeod

Quiz 1 Rules, Cont. Do not discuss the quiz with students who have not written it. Do not provide quiz answers to students who have not written it. The TAs will note the names of any “violators” and their quizzes will become zero! The rest of the lab time is available for assignment help. Winter 2019 CISC101 - Prof. McLeod

Preparing for Quiz 1 A “sample” version of this quiz is linked at the bottom of the “Grading” page. It will give you an idea of the type and quantity of questions on the quiz, including samples of coding questions. Do exercises 1 and 2. Start working on Assignment 1. Go over lecture notes, and videos if you need to. Winter 2019 CISC101 - Prof. McLeod

Today From last time: The Python Prompt and IDLE. Continue Python Syntax by looking at Expressions: Python Types Variables Operators (if we have time) Winter 2019 CISC101 - Prof. McLeod

Aside - The Python Prompt An open “pipeline” to the Python interpreter. You can always experiment using this prompt by writing small pieces of code. The prompt is never far away when you are using IDLE to build a Python program. Winter 2019 CISC101 - Prof. McLeod

The Python Prompt, Cont. <Cntrl>n will open up an empty editing window in IDLE. You first save, and then run any program you have written in IDLE. (Shortcut – press the <F5> function key when in IDLE to run your program – you will be prompted to save if you have not done so.) Anything stored in memory from a previous program that you have run is first deleted. (The “RESTART…” thing.) Then your program it is fed directly to the same Python Prompt, one line at a time. You can run your program again from the prompt by typing in main() followed by an <enter>. Winter 2019 CISC101 - Prof. McLeod

Python Expressions A program is a series of expressions, one per line. An expression is built from one or many of the following pieces: Literal values Variables Operators Keywords Function and method calls Punctuation Syntax supplies the rules about how these pieces go together so the interpreter can understand our commands. Winter 2019 CISC101 - Prof. McLeod

Numeric Types in Python CISC101 Numeric Types in Python In Exercise 1 you (have or will?) discovered that literal values can be of different types. What numeric types did you find? int float complex Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Numeric Types, Cont. Each type’s literal value is characterized by the way it is typed into a program. Do you remember the characteristics of each numeric type? How does the interpreter tell them apart? Winter 2019 CISC101 - Prof. McLeod

Numeric Types, Cont. The int type is an integer (no decimal or exponent) and there is no limit to its size. The float type is characterized by a decimal place and/or an exponent. It is limited to about 17 digits. (We won’t use the complex type much!) Winter 2019 CISC101 - Prof. McLeod

float Type For example to code the real number: You would write: 2.43E-4 or 2.43e-4 exponent decimal Winter 2019 CISC101 - Prof. McLeod

Other Bases Normally we view numbers in base 10, or in a “radix” of 10. That’s the default in Python. How can you create literal numbers in base 2, 8 or 16? Use the prefixes: 0b, 0o or 0x on literals. Use the BIFs: bin(), oct() and hex() to display a value in another base. Winter 2019 CISC101 - Prof. McLeod

Aside – What’s a “BIF”? (Not a Canadian Singer!) “Built-In Function”. Winter 2019 CISC101 - Prof. McLeod

Other Types What other types did you find? bool str How about the collections? bool str list tuple dict set We’ll talk more about these later… Winter 2019 CISC101 - Prof. McLeod

String Literals Characters enclosed in quotes. You can use: ' " """ or ''' The opening quote must match the closing quote. Examples: 'hello' "hello" """hello""" Winter 2019 CISC101 - Prof. McLeod

String Literals, Cont. Triple quoted strings can span multiple lines. (Can make for some really long strings - often used for documentation.) Winter 2019 CISC101 - Prof. McLeod

Python Types, Cont. Python determines the type of a literal value by examination. When the value is assigned to a variable, the variable is typed to match the type of the value. Python is a dynamically typed language. Which means that a variable can change types. Winter 2019 CISC101 - Prof. McLeod

From Exercise 1 – Literal Types What are the types of the following literals? 45.237 3.4e-7 45e10 123 0b100101 0x45cde 'Hello!' "Again" """line1 Line2""" True [4, 6, 7.9, "Dingdong"] (4, 5, True) {'first':'Alan', 'last':'McLeod'} {3, 4, 7, 10} "H" 3.4E10 Winter 2019 CISC101 - Prof. McLeod

From Exercise 1 – Types, Cont. How can you discover the type of a variable? How can you change a literal of one type to another? Winter 2019 CISC101 - Prof. McLeod

Variables What is a variable anyways? CISC101 Variables What is a variable anyways? In Python, variables are created by an assignment statement (or in a function’s parameter list). A variable takes the type of the value being assigned to it when the program runs. A variable’s value can change any time, as can its type. This is a convenient way to address a location in memory. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Assigning/Creating a Variable In code: myVal = 20 Now myVal refers to some location in RAM that stores the int type value 20. We don’t have to worry about what the actual memory address is. Winter 2019 CISC101 - Prof. McLeod

Variable Naming Syntax Rules Variable names are case sensitive. You can’t use a Python keyword for a variable name. No spaces! Start with a letter (use lower case, by convention), or an underscore_. The rest of the name can contain numbers, letters or the underscore (no spaces – oops I said that already!) Why no spaces, anyways? Winter 2019 CISC101 - Prof. McLeod

Variable Naming Style Rules Use descriptive names. Capitalize successive words in a name using camelCase. No limit to the length of a variable name, but don’t write an essay!! Don’t use single letter variable names, except if you need a loop counter that has no intrinsic meaning, then you can use i, j or k. Winter 2019 CISC101 - Prof. McLeod

Aside – The Worst Variable Name! My favourite bad variable name: l1 Winter 2019 CISC101 - Prof. McLeod

Arithmetic Operators As listed in Exercise 1: + addition Winter 2013 CISC101 Arithmetic Operators As listed in Exercise 1: + addition - subtraction (and unary negation) * multiplication / division // "floor" division % modulo or "remainder" ** exponentiation or "to the power of" The first four make sense, how do the last three work? Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

/ or Division For example, what is the value of 1 / 3 ? 0.3333333333333333 In previous versions of Python the result of int divided by int would be an int. Not any more! Now the result is a float. BTW, good thing there is a limit to the size of a float! Winter 2019 CISC101 - Prof. McLeod

// or Integer or “Floor” Division What is the value of 1 // 3? The result is always truncated, not rounded. So, 99 // 100 is also zero. You still get the truncated value, even if one or the other numbers are floats. So, 1.0 // 3.0 is still 0.0 Winter 2019 CISC101 - Prof. McLeod

% or “Modulo” Always gives the remainder after division. For example 20 % 3 is 2 Also works with floats. Result is a float. Winter 2019 CISC101 - Prof. McLeod

** or “To the Power Of” Example 5 ** 2 is 25 If both numbers are ints, the result is an int. You can generate some pretty large int values this way! For example 5 ** 100 is: 7888609052210118054117285652827862296732064351090230047702789306640625 If at least one number is a float, the answer is a float. So, 5.0 ** 100 is: 7.888609052210118e+69 Winter 2019 CISC101 - Prof. McLeod

Mixed Numeric Types If you have an expression like: aVal = 4 + 5 – 2.0 the result will always be a float. 7.0 in this case. So, if you get any float values in an expression that has integers the result will always be a float. So something like 4 + 10 / 5 gives 6.0 Winter 2019 CISC101 - Prof. McLeod

5 * ‘abc’ is ‘abcabcabcabcabc’ Strings and Numbers! Multiplication: 5 * ‘abc’ is ‘abcabcabcabcabc’ The + operator is the only other numeric operator that works with strings. Winter 2019 CISC101 - Prof. McLeod

Addition and Strings The + sign not only adds numbers but can also concatenate strings (and collections). Shall we try it out? You can concatenate a number to a string, but have to convert it to a string first using the str() BIF. Winter 2019 CISC101 - Prof. McLeod

Operators, Summary + - * / // % ** + - * / // % ** All of these work with numbers on both sides. Some will accept a string or even a collection on one side. If an expression has a float number in it, then the result will always be a float. Winter 2019 CISC101 - Prof. McLeod