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.

Slides:



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

If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
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?
Introduction to Python
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Python.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Programming.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Input & Output: Console
FUNCTIONS. Function call: >>> type(32) The name of the function is type. The expression in parentheses is called the argument of the function. Built-in.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Input, Output, and Processing
General Computer Science for Engineers CISC 106 Lecture 04 Dr. John Cavazos Computer and Information Sciences 09/10/2010.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Variables and Expressions CMSC 201 Chang (rev )
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.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
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.
Today… Python Keywords. Iteration (or “Loops”!) 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.
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 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
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:
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:
Topic: Python’s building blocks -> Variables, Values, and Types
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Topic: Python’s building blocks -> Variables, Values, and Types
Variables, Expressions, and IO
Winter 2018 CISC101 11/9/2018 CISC101 Reminders
Winter 2018 CISC101 11/15/2018 CISC101 Reminders
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Winter 2018 CISC101 11/29/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 Assn 3 due tomorrow, 7pm.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next 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:
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
CISC124 Labs start this week in JEFF 155. Fall 2018
Class 2.
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
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
General Computer Science for Engineers CISC 106 Lecture 03
CISC101 Reminders Assignment 3 due today.
CMPT 120 Lecture 4 – Unit 1 – Chatbots
Introduction to Python
Presentation transcript:

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 (“if” statements) are not on the quiz. Exercises 1 and 2 are fair game. You will need to understand conditionals for the assignment. 45 minutes on paper – no aids. Pen or pencil. First part of lab. Tell your TA if you cannot write in the first hour so he or she will expect you later in the lab. T/F, short answer, read code (“what is the output?”), write code (obtain something, calculate something else, display result). Returned in class, marks in Moodle. Winter 2016CISC101 - Prof. McLeod1

Winter 2016CISC101 - Prof. McLeod2 Today Features of Python. “Hello World” in a function definition. A program “template”. Python expressions.

CISC101 - Prof. McLeod3 Features of Python High Level –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 2016

CISC101 - Prof. McLeod4 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 2016

CISC101 - Prof. McLeod5 Features of Python, Cont. Robust –Exception handlers and 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. Winter 2016

Hello World 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 2016CISC101 - Prof. McLeod6

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 2016CISC101 - Prof. McLeod7

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 2016CISC101 - Prof. McLeod8

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. CISC101 - Prof. McLeod9Winter 2016

CISC101 - Prof. McLeod10 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 2016

CISC101 - Prof. McLeod11 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 2016

CISC101 - Prof. McLeod12 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 2016

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

CISC101 - Prof. McLeod14 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 2016

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

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. CISC101 - Prof. McLeod16Winter 2016

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

CISC101 - Prof. McLeod18 Variables What is a variable anyways? 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 2016

CISC101 - Prof. McLeod19 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 2016

CISC101 - Prof. McLeod20 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 2016

CISC101 - Prof. McLeod21 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 2016