Unit1-ProgrammingBasics
Introduction to OOP for Data Science
Course Name: DASC 12004 – Intro to Object Oriented Programming (Python)
Prof. John Gauch, Univ. of Arkansas, 2020
Updates by Prof. Lora Streeter
Programming Basics Overview
What is Computer Programming?
Objective: Provide detailed instructions for problem-solving to computers.
Importance of clarity and unambiguous writing.
Vast number of programming languages developed over 60 years.
Why Learn Python?
Python is a widely used, powerful programming language.
High-level, multi-paradigm (supports structured, object-oriented, and functional programming).
Extensive library of functions available for diverse problem-solving.
Software Development Cycle
Evolution of programming tools and techniques over 50 years.
Conversion of abstract goals into structured instructions (Python code).
Classic software development cycle stages:
Plan: Determine the problem, input, and expected output.
Design: Decompose the problem into smaller, solvable steps.
Implement: Write code utilizing existing libraries.
Test: Validate program behavior with normal and erroneous inputs.
Release: Launch program for users, gather feedback for improvements.
Programming Strategies
Approaches to program creation:
Manager: Acquire solutions partially or fully from others.
Mimic: Enhance existing solutions.
Inventor: Create solutions from scratch.
Becoming proficient:
Familiarize with tools, patterns, and extensive practice.
Learning Objectives
Understand Python program structure.
Learn about input/output mechanics, variables, and data types.
Complete a programming project using fundamental programming concepts.
Programming Basics Part 1: What Makes a Program?
Basic Functionality of a Program
Programs are sequences of instructions for the computer.
Unique syntactical rules govern each programming language (syntax).
Semantic understanding is necessary for interpreting program instructions.
Structure of a Python Program
Comments: Explain the purpose of the program.
Import Commands: Access existing function libraries.
Classes and Methods: Breakdown of problems (to be covered later).
Main Method: Where variables and program statements reside.
Example Python Program:
Code:
print('Hello there')Function of the comment and print statement explained.
Programming Basics Part 2: Storing Data
Variables and Data Types
Common Python data types include:
Integer: Whole numbers (int).
Float: Decimal numbers (float).
Boolean: True/False values (bool).
String: Textual data (str).
Range: Sequence of integers.
List: Collection of items.
Tuple: Immutable collections.
Dictionary: Key-value pairs.
Variable Usage
Variables used to store/manipulate data, memory consumed is type-dependent.
Implicit data type declaration based on assigned value:
Examples: Assigning integer, string, float values.
Variable Naming Conventions
Names must start with a letter/underscore; contain no spaces.
Examples of illegal variable names.
Suggest meaningful, readable names.
Constants
Constants should remain unchanged throughout the program; indicated by UPPERCASE names.
Programming Basics Part 3: Program Input / Output
Input and Output Process
Input commands read user keyboard entries; output commands write to the screen.
Typical program pattern:
User interaction and calculation based on input.
Introduction to
input()for input commands andprint()for output.
Input Characteristics
Default behavior of
input(): returns values as strings; conversion examples given.
Python Print Function
Syntax:
print(output)displays data.Processing of data types during printing.
Controlling line breaks in output using
endparameter.
Programming Basics Part 4: Numerical Calculations
Arithmetic Expressions
Syntax comprises values and arithmetic operators (+, -, *, /, //, %, **).
Order of operations similar to mathematical rules (precedence rules discussed).
Evaluation of Expressions
Order of execution based on precedence; evaluation examples provided.
Data Type Handling
Implicit vs. explicit type conversions discussed through examples including type casting.
Conclusion
Summary of Python data storage procedures, input/output mechanisms, and numerical calculations.
Highlighted the importance of clarity through comments and meaningful coding practices.
Practical application through sphere volume and area calculation example, emphasizing importation of libraries and clean interactions.