Computer Programming Fundamentals

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 8 Fruitful Functions 05/02/09 Python Mini-Course: Day 2 - Lesson 8 1.
Advertisements

Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Structured programming
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
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.
Functions Chapter 4 Python for Informatics: Exploring Information
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
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.
Lists COMPSCI 105 S Principles of Computer Science.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
Functions Chapter 4 Python for Informatics: Exploring Information Slightly modified by Recep Kaya Göktaş on March 2015.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
Chapter 2 Writing Simple Programs
String and Lists Dr. José M. Reyes Álamo.
PH2150 Scientific Computing Skills
Recap: If, elif, else If <True condition>:
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Python: Experiencing IDLE, writing simple programs
CSc 120 Introduction to Computer Programing II Adapted from slides by
Module 5 Working with Data
Introduction to Python
Python: Control Structures
CS-104 Final Exam Review Victor Norman.
Computer Programming Fundamentals
Presented By S.Yamuna AP/IT
Python - Functions.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Repetition: the for loop
While Loops in Python.
Engineering Innovation Center
PH2150 Scientific Computing Skills
CISC101 Reminders Quiz 2 this week.
PYTHON Varun Jain & Senior Software Engineer
Lists in Python.
Nate Brunelle Today: Repetition, A Trip To The Moon
Object Oriented Programming (OOP) LAB # 5
CS190/295 Programming in Python for Life Sciences: Lecture 6
Count Controlled Loops
Chapter (3) - Looping Questions.
4. sequence data type Rocky K. C. Chang 16 September 2018
String and Lists Dr. José M. Reyes Álamo.
Lists in Python Creating lists.
Introduction to Python: Day Three
Introduction to Python
Python for Informatics: Exploring Information
Introduction to Value-Returning Functions: Generating Random Numbers
Python Basics with Jupyter Notebook
CISC101 Reminders Assignment 2 due today.
Repetition: the for loop
COMPUTER PROGRAMMING SKILLS
Introduction to Computer Science
General Computer Science for Engineers CISC 106 Lecture 03
Topic: Loops Loops Idea While Loop Introduction to ranges For Loop
While Loops in Python.
Class code for pythonroom.com cchsp2cs
Variables and Constants
COMPUTING.
Introduction to Computer Science
Presentation transcript:

Computer Programming Fundamentals Recap session

Agenda Variables Lists ‘if-elif-else’ Loops Modules and functions ‘while’ loop ‘for’ loop Modules and functions Putting it all together

Variables Chunks of the computer’s memory Each has a name Starting with alphabetic character Then can be alphabetic or numeric character Cannot use keywords Each has a type int: integer bool: Boolean value str: string

Lists Lists are an extremely versatile Python data type They are used frequently so it is important to get to know how to use them The elements of a list can be anything: myList = ["Abc", 1, 3.8, True] A list can even have no items: emptyList = []

Lists The elements of a list may be modified: Some other operations: myList = ["Abc", 1, 3.8, True] myList[0] = "ABCD" Some other operations: myList.append("DEF") myList.extend(["GHI",99]) myList.clear() myList.pop(i) del myList[i]

‘if-elif-else’ Use to pick different execution paths if score < 10: print("Pathetic") elif score < 20: print("My gran could do better") elif score < 50: print("OK") else: print("Legendary!!!")

The ‘while’ loop We can make the computer repeat statements One way to do this is to use a ‘while’ loop For example The body of the loop is executed while the condition x > 0 is true a = 1 x = 10 while x > 0 : a = a*x x = x - 1

The ‘for’ loop Another kind of loop is a ‘for’ loop which iterates over the elements of a list We can use the ‘range’ built-in function to make a ‘for’ loop iterate over integers: for x in range(4): print(x) This will print the numbers 0,1,2,3 L = ["Abc", 1, 3.8, True, "XYZ", 21] for e in L: print(e)

Functions Functions are a way of packaging useful chunks of code We give the code a name so it can be re-used We can tailor how the function behaves by the use of arguments The function may or may not return a value

Modules Modules are a convenient way to package groups of related functions Defining a module is very easy Create a new file – ‘shapes.py’ for instance Add function definitions to the file Example – ‘shapes.py’ # Utility functions for dealing with shapes def circleArea(radius=1): ... def rectangleInfo(width,height):

Putting it all together Generating lottery numbers Generate random numbers in a range Need 6 different numbers 11

Exercises An exercise in using random numbers Write a program to generate lottery numbers