PYTHON Prof. Muhammad Saeed.

Slides:



Advertisements
Similar presentations
Μαθαίνοντας Python [Κ4] ‘Guess the Number’
Advertisements

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.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Geography 465 Assignments, Conditionals, and Loops.
CIS 234: Character Codes Dr. Ralph D. Westfall April, 2011.
Python Control of Flow.
Program Elements -- Introduction
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Python  By: Ben Blake, Andrew Dzambo, Paul Flanagan.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Announcements Project 2 Available Tomorrow (we will send mail) Will be due 11:59PM October 9 th (Sunday) Week 6 ( I will be traveling this week) Review.
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
C-Language Keywords(C99)
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 12 More about strings 05/02/09 Python Mini-Course: Day 3 – Lesson 12.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
CSI2172
Rina System development with Java Instructor: Rina Zviel-Girshin Lecture 2.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Monday, September 8, 2014 CSCI 351 – Mobile Applications Development.
Characters and Character Sets tMyn1 Characters and Character Sets The characters that can be used are the upper and lower case letters, A to Z and a to.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
Chapter 5 Strings CSC1310 Fall Strings Stringordered storesrepresents String is an ordered collection of characters that stores and represents text-based.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Python if.
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
(Monty) Python for loops Mr. Neat. Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide()
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
File Processing CMSC 120: Visualizing Information Lecture 4/15/08.
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:
G. Pullaiah College of Engineering and Technology
Do-more Technical Training
CSC 4630 Meeting 7 February 7, 2007.
Chapter 3 Data Representation Text Characters
Chapter-01 A Sample C++ Program.
CSc 120 Introduction to Computer Programing II Adapted from slides by
ECE Application Programming
Python: Control Structures
Chapter 2 Data Types and Representations
Javascript, Loops, and Encryption
Variables, Types and Expressions
Variables, Types and Expressions
Arithmetic operations, decisions and looping
C++ Basics.
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Basics of ‘C’.
An overview of Java, Data types and variables
An Introduction to Python
“If you can’t write it down in English, you can’t code it.”
More Looping Structures
Suggested Layout ** Designed to be printed on white A3 paper.
PYTHON Prof. Muhammad Saeed.
(more) Python.
functions: argument, return value
CISC101 Reminders All assignments are now posted.
Module 2 - Part 1 Variables, Assignment, and Data Types
Java Programming Language
COMPUTER PROGRAMMING SKILLS
CISC101 Reminders All assignments are now posted.
More Looping Structures
CSE 231 Lab 2.
More Basics of Python Common types of data we will work with
Odds and Ends.
Introduction to Python
Strings As well as tuples and ranges, there are two additional important immutable sequences: Bytes (immutable sequences of 8 ones and zeros (usually represented.
Presentation transcript:

PYTHON Prof. Muhammad Saeed

Python Dept. Of Comp. Sc. & IT, FUUAST Programming In Python Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming Case-sensitive Object Oriented Every identifier is an object Indentation replaces blocks for ‘function’, ‘If’, ‘else’, ‘elif’, ‘for’, ‘while’ etc. First line for ‘function’, ‘If’, ‘else’, ‘elif’, ‘for’ and ‘while’ is terminated at colon(:) Multiple assignments are allowed as x, y, z= 0,10,-3 Packages are imported into programs as: import scipy import scipy as sp from scipy import * from scipy import sin, cos, exp Hierarchy: Project Package Module Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming input/output print name=‘FUUAST ’ city=‘Karach i’ print(name + ‘Gulshan Campus ’+city) age=25; s=2.555; continent=‘Asia’; nm=‘Ali’ print(‘My name is %s, my age is %d,my salary is %6.3f million pm and I live in %s’%(nm, age, s, continent)) print(age,s,nm) print(‘\nName: {0}\nAge: {1}\nSalary: {2}\n’.format(nm,age,s)) input n=input(‘Enter a number: ’) sts=input(‘Enter names: ‘) Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming escape sequences Escape What it does. \\ Backslash (\) \' Single-quote (') \" Double-quote (") \a ASCII bell (BEL) \b ASCII backspace (BS) \f ASCII formfeed (FF) \n ASCII linefeed (LF) \N{name} Character named name in the Unicode database (Unicode only) \r Carriage Return (CR) \t Horizontal Tab (TAB) \uxxxx Character with 16-bit hex value xxxx (u'' string only) \Uxxxxxxxx Character with 32-bit hex value xxxxxxxx (u'' string only) \v ASCII vertical tab (VT) \ooo Character with octal value ooo \xhh Character with hex value hh Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming Decision & Loops x=-1; if x > 0: print(‘x is positive’) print(‘Good, keep it up’) elif x == 0: print(‘x is nobody’) print(‘Be practical’) elif x < 0: print(‘x is negative’) print(‘Try to be positive’) else: print(‘Be something’) for i in range(1,20): r=i%2 if r==0: print(‘\nNumber %d is Even’%(i)) print(‘\nNumber %d is Odd’%(i)) print(‘Thanks’) Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming Loops bigms = [‘Books',‘Internet',‘Games’,’Movies’,’Songs’] for i in range(len(bigms)): print("I like",bigms[i]) n = 100; sm = 0; i = 1 while i <= n: sm = sm + i i = i + 1 print("Sm of 1 until %d: %d" % (n,sm)) count = 0 while count < 5: print( count, ’ is less than 5’ ) count = count + 1 else: print( count, " is not less than 5“) flag=1 while (flag): print( ‘Job is done‘) Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming Nested Loops, break, continue, pass p=np.zeros([10,5]) for n in range(10): for m in range(5): p[n,m]=m*n sm=sum(sum(p)) print(p,’\n\n’,sm) for c in ‘University': if c == ‘v': break print('Current Character : ', c) continue Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming Nested Loops, break, continue, pass for c in ‘University': if c == ‘v': pass print('Current Character : ', c) d=np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]) y=[x**2 for x in d if x%4==0] Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming Functions def evenodd(n): if (n%2==0): print(‘\nEven’) else: print(‘\nOdd’) def addsubtract(a,b): if a>b: return a-b else : return a+b vec_addsubtract = vectorize(addsubtract) vec_addsubtract([0,3,6,9],[1,3,5,7]) f=lambda x, y: 2*x**2-3*x*y+5*y**2+4*x-2*y+10; f(2.5, 3) nums = [2, 18, 9, 22, 17, 24, 8, 12, 27] flt=filter(lambda x: x % 3 == 0, nums); print(*flt) Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming Default Arguments def funct(x,str1='Hello',y=1,str2='Hi'): print(x,str1,y,str2) funct(50, str2='ASA', str1='abc', y='nn') funct(16,’Karachi’, 200,’ Lahore’) funct(225) funct(25,’Quetta’) def quote(): ""“ There are no tales finer than those created by life itself. ---------------------------------------------------------- """ pass print(quote.__doc__) Special Functions: import scipy.special sum; sumcum; prodcum; Python Dept. Of Comp. Sc. & IT, FUUAST

Python Dept. Of Comp. Sc. & IT, FUUAST Programming END Python Dept. Of Comp. Sc. & IT, FUUAST