Download presentation
Presentation is loading. Please wait.
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! ( Courses it is useful in:Wireless Systems,Networking,Analog & Digital Systems
5
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
6
Key Features 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. compile execute output source code Hello.java byte code Hello.class interpret output source code Hello.py
7
Key Features Python is Interactive Python is Object-oriented
Python is a Beginner's Language
8
Lets get started!! Python Official Website :
9
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 # Number Game:Program that takes any 2-digit number and outputs a 6-digit number,having the 2-digit repeated.For-example,24 becomes
10
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 Command name Description abs(value) absolute value ceil(value) rounds up cos(value) cosine, in radians floor(value) rounds down log(value) logarithm, base e log10(value) logarithm, base 10 max(value1, value2) larger of two values min(value1, value2) smaller of two values round(value) nearest whole number sin(value) sine, in radians sqrt(value) square root Constant Description e pi
11
Program #2 Program #02 Saving Interest Program
Concepts:String Formatting,Functions,Modules
12
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: elif condition: Program #3 Tweet Decoder:Write a program that decodes a few common abbreviations (tweets) or and provides the corresponding English Phrase.
13
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 };
14
Program Extract IP address program
15
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
16
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
17
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
18
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., HOLIDAY). The program then outputs the phone number using numbers only.
19
Continued.. Session :02 OOP
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.