CSCI/CMPE 4341 Topic: Programming in Python Review: Final Exam Xiang Lian The University of Texas – Pan American Edinburg, TX 78539

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Structured programming
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
ASP.NET Programming with C# and SQL Server First Edition
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
Chapter 13: Object-Oriented Programming
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Fundamentals of Python: From First Programs Through Data Structures
Visual Basic Chapter 1 Mr. Wangler.
The University of Texas – Pan American
Fundamentals of Python: First Programs
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
The University of Texas – Pan American
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Linux+ Guide to Linux Certification, Third Edition
If statements while loop for loop
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam II Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 5: Functions Xiang Lian The University of Texas – Pan American Edinburg, TX
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
1 PL\SQL Dev Templates. 2 TEMPLATE DEFINITION Whenever you create a new program unit, its initial contents are based upon a template which contains pre-defined.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 4: Control Structures (Part 2) Xiang Lian The University of Texas – Pan American Edinburg, TX
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
REEM ALMOTIRI Information Technology Department Majmaah University.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 5: Functions – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Visual Basic.NET Windows Programming
Topics Introduction to Functions Defining and Calling a Void Function
Topics Graphical User Interfaces Using the tkinter Module
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Functions.
JavaScript: Functions.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
The University of Texas – Pan American
Arithmetic operations, decisions and looping
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Review: Exam I
The University of Texas – Pan American
CSCI 3327 Visual Basic Review: Final Exam
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Review: Exam I
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 3327 Visual Basic Review: Exam I
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
Topics Introduction to Functions Defining and Calling a Function
The University of Texas – Pan American
Class code for pythonroom.com cchsp2cs
CSCI 3328 Object Oriented Programming in C# Review: Exam II
Presentation transcript:

CSCI/CMPE 4341 Topic: Programming in Python Review: Final Exam Xiang Lian The University of Texas – Pan American Edinburg, TX

Review Textbook –Self-Review Exercises –Quick Quiz –Exercises Time –8am - 9:45am, May 14 (Thursday) Place –ENGR (classroom) 2

Review Lecture slides –Basic concepts in Python –Control Structures –Functions –Lists, Tuples, and Dictionaries –Introduction to Object-Oriented Programming –Graphical User Interface Components –Python XML Processing –Database & SQL 3

Review Multiple Choices True/False Statements Programming –Debugging –Write the code Bonus Question 4

Chapter 1: Python Python is a scripting language –It is not compiled as an executable file Python –Structured programming Divide and conquer –Object-oriented programming Class and object –Data encapsulation –Inheritance –Polymorphism 5

Chapter 2: Basic Concepts in Python Programming Arithmetic operators and their precedence Commonly used Python rules/functions –print() 6

Arithmetic Operators Symbols –* # multiply –/ # divide –% # modulus –** # exponential –// # floor division Order –Operators are done in order of parenthesis, exponents, multiply and divide (left to right), and lastly add and subtract (left to right) 7

Chapters 3 & 4: Control Structures The syntax of basic sequence, selection, and repetition structures in Python –Selection if, if/else, if/elif/else –Repetition while, for 8

Syntax of Control Structure 9 total = total + Grade counter = counter + 1 if Grade>=60: print ("Passed") if Grade>=60: print ("Passed") else: print ("Failed")

10 for Repetition Structure The for loop –Function range is used to create a list of values –range ( integer ) »Values go from 0 to given integer –range ( integer1, integer2) »Values go from first up to second integer –range ( integer1, integer2, integer ) »Values go from first up to second integer, but increases in intervals of the third integer –The loop will execute as many times as the value passed –for counter in range ( value ): [0, integer-1] [integer1, integer2-1] 10

Chapter 5: Functions Modules and pre-defined functions –import moduleName –math math.floor () math.ceil () –random random.randrange() Syntax of user-defined functions 11

12 Module math Functions Module –Contains function definitions and other elements All of which are related in some way –Calling a function functionName ( argument1, argument2 ) –The import keyword is used to include a module –Invoking functions from a module Use the module name followed by the dot operator (.) moduleName.functionName( argument )

13 Random-Number Generation The random module –Used to generate a random number for the programmer –Function randrange Generates a number from the first argument up to, but not including, the second argument Each number in the range has the same likelihood of being selected by the function –random.randrange(a, b)

14 User-Defined Functions Definitions –Functions must be defined before they are used –def functionName ( paramList ): functionName is a valid identifier paramList is a comma separated list of parameters received The actions of the functions then follows –They should all be indented appropriately –The actions are also called the block or the function body

Chapter 6: Lists, Tuples, and Dictionaries Creation and manipulation of sequences –String –List –Tuple 15

Example of Sequences C[0]-45C[-12] C[1]6C[-11] C[2]0C[-10] C[3]72C[-9] C[4]34C[-8] C[5]39C[-7] C[6]98C[-6] C[7]-1345C[-5] C[8]939C[-4] C[9]10C[-3] C[10]40C[-2] C[11]33C[-1] Name sequence (C) Position number of the element within sequence C 16

Creating Sequences – List Lists –Use brackets –Separate multiple items with a comma list1 = [1, 2, 3, 4] –Empty list list2 = [] Length of the list –len (list1) list1[0]=0 # OK! 17

Creating Sequences – Tuple Tuples –Use parenthesis –Separate multiple items with a comma tuple1 = (1, 2, 3, 4) tuple1 = 1, 2, 3, 4 –Empty tuple tuple2 = () –Singleton (or one-element tuple) singleton3 = 1, Comma (,) after 1 identify the variable signleton3 as a tuple Error! –tuple1[0]=0 18

Chapter 7: Introduction to Object- Oriented Programming in Python Classes –Attributes Private attributes Class attributes –Methods Constructor: __init__ Get and Set methods Destructor: __del__ Objects –Creation of objects Inheritance 19

Class Declaration Defining a Class –Class header Keyword class begins definition –Followed by name of class and colon (:) –Body of class Indented block of code –Documentation string Describes the class Optional Appears immediately after class header 20

Class Declaration (cont'd) Defining a Class –Constructor method __init__ Executes each time an object is created Initialize attributes of class Returns None –Object reference (self) All methods must at least specify this one parameter Represents object of class from which a method is called Called self by convention 21

Get and Set Methods Access methods –Allow data of class to be read and written in controlled manner –Get and Set methods Allow clients to read and write the values of attributes respectively 22

Destructors –Method is named __del__ –Executed when object is destroyed No more references to object exist –Performs termination housekeeping before Python reclaims object memory Typically used to close network or database connections 23

Chapter 8: Graphical User Interface Components Components –Label –Entry –Button –Checkbutton & Radiobutton 24

Entry Component – TextBox Textbox –Areas in which users can enter text or programmers can display a line of text –Created by Entry class event occurs when user presses Enter key inside Entry component 25

Checkbutton and Radiobutton Components Checkbox –Small white square –Either blank or contains a checkmark –Descriptive text referred to as checkbox label –Any number of boxes selected at a time –Created by class Checkbutton Radio button –Mutually excusive options – only one radio button selected at a time –Created by class Radiobutton Both have on/off or True/False values and two states – selected and not selected (deselected) 26

Chapter 9: Python XML Processing XML documents –Tree structure –Tags –Elements –Data 27

Chapter 10: Database & SQL Relational database –Database schema –A set of relational tables SQL (Structured Query Language) –A database language –Syntax of SQL Use Python to submit SQL to databases 28

Example of Table: Employees 29

SQL A program might select data from the table to create a query result – E.g., to retrieve the location of each department, in increasing order by Department number – SQL: SELECT DISTINCT Department, Location FROM Employees ORDER BY Department 30

SQL Results 31

SQL on Books Database SELECT * FROM tableName – SELECT * FROM Authors – SELECT AuthorID, LastName FROM Authors SELECT columnName1, columnName2, … FROM tableName WHERE criteria – SELECT Title, EditionNumber, Copyright FROM Titles WHERE Copyright > '2014' 32

Example of Using pyodbc Package abase_Programming import pyodbc DBfile = '/data/MSAccess/Music_Library.mdb' conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+DBfile) #use below conn if using with Access 2007, 2010.accdb file #conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+DBfile) cursor = conn.cursor() SQL = 'SELECT Artist, AlbumName FROM RecordCollection ORDER BY Year;' for row in cursor.execute(SQL): # cursors are iterable print (row.Artist, row.AlbumName) # print row # if print row it will return tuple of all fields cursor.close() conn.close() 33

Good Luck! Q/A