Winter 2018 CISC101 11/15/2018 CISC101 Reminders

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
CIS Computer Programming Logic
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Programming With C.
Computer Science 101 Introduction to Programming.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
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.
CPS120: Introduction to Computer Science Variables and Constants.
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.
Winter 2016CISC101 - Prof. McLeod1 Today Go over the Python disassembly “experiment” again. Code interpretation vs. code compilation. History and features.
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.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
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.
A Python Tour: Just a Brief Introduction
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Python: Experiencing IDLE, writing simple programs
CSCI-235 Micro-Computer Applications
Introduction to Python
Variables, Expressions, and IO
Functions CIS 40 – Introduction to Programming in Python
Application Development Theory
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/22/2018 CISC101 Reminders
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
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
CISC101 Reminders Quiz 2 this week.
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
Introduction to Programming with Python
Class 2.
Introduction to Computer Programming
CISC101 Reminders All assignments are now posted.
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.
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.
12th Computer Science – Unit 5
CISC101 Reminders All assignments are now posted.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
General Computer Science for Engineers CISC 106 Lecture 03
CISC101 Reminders Assignment 3 due today.
Winter 2019 CISC101 5/30/2019 CISC101 Reminders
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Winter 2018 CISC101 11/15/2018 CISC101 Reminders Your group name in onQ is your grader’s name. Let me know if you are not in a group. Prof’s office hours set to Thursdays 1:45 to 2:30 in GOO 550. More times will be added, if needed. Winter 2018 CISC101 - Prof. McLeod Prof. Alan McLeod

Today From last week: Origins and History of Python. How commands must be translated to binary for the CPU to be able to process them. Upper level languages like Python are translated to Assembler which is then translated to machine code for execution. Origins and History of Python. The “Hello World” Ritual. If we have time: Start Python Expressions. Winter 2018 CISC101 - Prof. McLeod

Computer Languages: History People became a bit frustrated with Assembler! The next generation of computer languages went up one more level, getting closer to something readable - for example: Fortran, Cobol and Lisp. These languages led to an explosion of over 200 languages being developed in the 60’s and 70’s, such as Basic, Pascal, C, Ada and Smalltalk. Python is a relative newcomer, arriving on the scene in the early 90’s. Winter 2018 CISC101 - Prof. McLeod

Aside – 99 Bottles of Beer… See: http://www.99-bottles-of-beer.net/ Programs in 1500 different programming languages to generate the lyrics to the “song”. Winter 2018 CISC101 - Prof. McLeod

Aside - Malbolge A programming language designed to be extremely hard to program in and impossible to read. Named after the eighth circle of Hell in Dante’s “Inferno”. Featured in an episode of Elementary (S01E10). They supposedly had a program in Malbolge that de-crypted a safe’s combination. What they really had was “Hello World” in Malbolge: Winter 2018 CISC101 - Prof. McLeod

“Hello World” in Malbolge ('&%:9]!~}|z2Vxwv-,POqponl$Hjig%eB@@>}=<M:9wv6WsU2T|nm-,jcL(I&%$#" `CB]V?Tx<uVtT`Rpo3NlF.Jh++FdbCBA@?]!~|4XzyTT43Qsqq(Lnmkj"Fhg${z@> Winter 2018 CISC101 - Prof. McLeod

Yikes! Python is much, much friendlier!! “Hello World” in Python: print("Hello World") Winter 2018 CISC101 - Prof. McLeod

CISC101 History of Python The language was created by Guido van Rossum at Stichting Mathematisch Centrum in the Netherlands in the early 90’s. He is still very involved with the language and retains the title “BDFL”, which stands for “Benevolent Dictator for Life”. Python is named after “Monty Python”, not the snake!! Winter 2018 CISC101 - Prof. McLeod Prof. Alan McLeod

History of Python, Cont. He wanted to make the language: an easy and intuitive language, but just as powerful as major competitors. open source, so anyone can contribute to its development. use code that is as understandable as plain English. to be suitable for everyday tasks, allowing for short development times. First released in 1994, the language was inspired by Modula-3, Lisp, SETL, Haskell, Icon and Java. A compilation of all the “Best-Of’s” from many other languages! Winter 2018 CISC101 - Prof. McLeod

Features of Python High Level Object Oriented Scalable Extensible Most notable are the built-in data structures. Object Oriented OOP helps you to build code in a modular way. But, Python allows you to write code without knowing anything about OOP! Scalable Packaging of code allows even very large programming projects to be manageable. Extensible You can easily use external code modules written in Python, C, C++, C#, Java or Visual Basic. Winter 2018 CISC101 - Prof. McLeod

Features of Python, Cont. Portable Runs on any platform/OS combination that can run C. Easy to Learn (!) Relatively few keywords, simple language structure and clear syntax. OOP can be avoided while learning. Easy to Read Much less punctuation than other languages. Forces you to use good indentation. Easy to Maintain Results from the two above features! Winter 2018 CISC101 - Prof. McLeod

Features of Python, Cont. Robust Exception handlers provide safe, sane and informative crashes. Good for Rapid Prototyping Often used with other languages to create prototypes and provide a testing platform. Built-In Memory Management Like Java. Avoids a major problem in C/C++. Interpreted Not compiled – each command is executed as it is read from the program. (Speed can be increased a bit using byte-compiled files (like Java does).) Winter 2018 CISC101 - Prof. McLeod

“Easter Egg” Execute the command import this at the Python prompt… For more detail on the history of Python, see: https://www.youtube.com/watch?v=ualxVE4YOjc Winter 2018 CISC101 - Prof. McLeod

Hello World Ritual Print “Hello World” at the >>> prompt. Do the same thing from a script, or “program”. Write a program that prompts the user for his first name and then displays “Hello name” to the console. Put the code in a main function. Just for fun, disassemble the program when it is done. Winter 2018 CISC101 - Prof. McLeod

Questions Do you have to put code in a main function? Why is it called “main()”? What’s with the “()”? They are empty! Why is there a call to main() at the end of the program? How can you tell what code is inside main() and what is outside? Winter 2018 CISC101 - Prof. McLeod

Questions, Cont. What does the input() BIF return? How can you get a number, like an int, from input()? What does the print() BIF return? What does “+” do with strings? I can add numbers with “+”, as well. Can I add a number to a string? Winter 2018 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 Keywords Function and method calls Punctuation “Syntax” supplies the rules about how these pieces go together so the interpreter can understand our commands. Winter 2018 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 2018 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 type? How does the interpreter tell them apart? Winter 2018 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 2018 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 2018 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 2018 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 2018 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 2018 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 2018 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 2018 CISC101 - Prof. McLeod

CISC101 Variables A variable is a name used in a program to refer to a specific location of memory. In Python, variables are created by an assignment statement (or in function parameter lists). 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. Winter 2018 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 2018 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. Why no spaces, anyways? Winter 2018 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 2018 CISC101 - Prof. McLeod

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