1 / 19

Faiza Qadri Graduate Student,Department of Engineering,SSU Society of Women Engineering Session:01

Introduction to programming with Python. Faiza Qadri Graduate Student,Department of Engineering,SSU Society of Women Engineering Session:01. Languages. Why is it important.

ulloa
Download Presentation

Faiza Qadri Graduate Student,Department of Engineering,SSU Society of Women Engineering Session:01

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to programming with • Python Faiza Qadri Graduate Student,Department of Engineering,SSU Society of Women Engineering Session:01

  2. Languages

  3. Why is it important • Python started as a scripting language for Linux like Perl but less cryptic. Now it is used for both web and desktop applications and is available on Windows too. • According to IEEE Spectrum,its one of the top 5 software languages • Must have skill for a Software Engineer! • One of the official languages at Google • NASA uses Python! (https://www.python.org/about/success/usa/) • Courses it is useful in:Wireless Systems,Networking,Analog & Digital Systems

  4. A little History • Python programming language was created by Guido Van Rossum in 1991 at at the National Research Institute for Mathematics and Computer Science in the Netherlands. • The inventor is a fan of "Monty Python's Flying Circus", a comedy series from the seventies. • Python is derived from many other languages, including C, C++, SmallTalk, and Unix shell and other scripting languages. • Its design philosophy emphasizes code readability

  5. Key Features • interpret • compile • execute • source code • Hello.java • byte code • Hello.class • output • source code • Hello.py • output • Python is a high-level,interpreted,interactive and object-oriented scripting language • Python is Interpreted:Similar to PERL and PHP • Many languages require you to compile (translate) your program into a form that the machine understands. • Python is instead directly interpreted into machine instructions.

  6. Key Features • Python is Interactive • Python is Object-oriented • Python is a Beginner's Language

  7. Lets get started!! • Python Official Website : http://www.python.org/

  8. Program #1 • (Input ,Print) • Input: Reads a number from user input. • You can assign (store) the result of input into a variable. • Example: age = input("How old are you?”) n=eval(input(‘enter the input’)) print (“Your age is", age) print (“You have", 65 - age, "years until retirement”) • print : Produces text output on the console. • Syntax: print (“Message”) print (Expression) • Program #1 Number Game:Program that takes any 2-digit number and outputs a 6-digit number,having the 2-digit repeated.For-example,24 becomes 242424.

  9. Math commands • Python has useful commands for performing calculations. • To use many of these commands, you must write the following at top of your Python program: • import math

  10. Program #02 Program #2 • Saving Interest Program • Concepts:String Formatting,Functions,Modules

  11. Branching Branching • A program should be able to execute different statements depending on calculations or users input. • If-else if expression: statements else: Statements if expression is false Statements here execute after the if-else. • Multiple if-else,Use elif i if condition: statements elif condition: statements else: statements • Program #3 Tweet Decoder:Write a program that decodes a few common abbreviations (tweets) or email and provides the corresponding English Phrase.

  12. Lists & Dicts • A list is a container, which is an object that groups related objects together. • A list is also a sequence; thus, the contained objects maintain a left-to-right positional ordering.For example list1 = ['physics', 'chemistry', 1997, 2000]; list 2=[1,2,3,4,5]; list3 = [“a”,“b”,“c”,“d”] • List Methods:list.append(x) , list.insert(i,x) , list.remove(x), list.pop(0) • A dictionary is another sort of type of container • Dictionaries contain references to objects as key-value pairs – each key in the dictionary is associated with a value .For-example dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': ‘3258'} dict1 = { 'abc': 456 }; dict2 = { 'abc': 123, 98.6: 37 };

  13. Program • Extract IP address program

  14. Loops Programmer can use a loop that executes the same code over and over again as long as some condition is true. While Loop while expression: # Loop expression # Loop body: Sub-statements to execute... # if the loop expression evaluates to True... # Statements to execute after the expression evaluates to False

  15. Loops For Loop Syntax for variable in container: # Loop body: Sub-statements to execute # for each item in the container # Statements to execute after the for loop is complete Example:Square of a Number: for x in range(1, 6): print (“squared is", x * x) Program #4 Write a program to find the Factorial of a number(Use While or For Loop)’ Notes:2 things about loops:No of times we want to run the loop,There has to be an exit condition

  16. Nested Loops • Loop inside a loop • Program#05 Write a program that uses a nested for-loop to find the prime numbers from 2 to 100

  17. Program #06 • Phone Number Program • Program allows the user to enter a phone number that includes letters, which appear on phone keypads along with numbers, as is commonly used by companies as a marketing tactic (e.g., 1-555-HOLIDAY). The program then outputs the phone number using numbers only.

  18. Continued.. • Session :02 • OOP

More Related