Example: dental hygienist

Basics of Python Programming

Informatics PracticesClass XI ( Asper CBSEB oard)Chapter 5 Basics ofPython ProgrammingNew syllabus 2020-21 Visit : for regularupdatesBasics of Python ProgrammingStructureofapythonprogramProg ram|->Module -> main program|-> functios|->libraries|->Statements -> simple statement|->compound statement|->expressions -> Operators|-> expressions|---- objects ->data modelVisit : for regular updatesPython , Character : A-Z,a-zDigits : 0-9 Special symbols : Special symbol available over keyboard White spaces: blank space,tab,carriagereturn,newline, form feedOther characters:-UnicodeVisit : for regular updatesInput and OutputVisit : for regular updatesvar1= Computer Science'var2= Informatics Practices'print(var1,' and ',var2,' )Output :-Computer Science and Informatics Practicesraw_input()Function In Python allows a user to give input to a program from a keyboard but in the form of : raw_input() function is deprecated in Python = int(raw_input( enter your age ))percentage = float(raw_input( enter percentage ))input()Function In Python allows a user to give input to a program from a keyboard but returns the value age = int(input( enter your age ))C = age+2 #will not produce a

Python basics Python 3.0 was released in 2008. Although this version is supposed to be backward incompatibles, later on many of its important features have been back ported to be compatible with version 2.7 Python Character Set A set of valid characters recognized by python. Python uses the traditional ASCII character set.

Tags:

  Basics

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Basics of Python Programming

1 Informatics PracticesClass XI ( Asper CBSEB oard)Chapter 5 Basics ofPython ProgrammingNew syllabus 2020-21 Visit : for regularupdatesBasics of Python ProgrammingStructureofapythonprogramProg ram|->Module -> main program|-> functios|->libraries|->Statements -> simple statement|->compound statement|->expressions -> Operators|-> expressions|---- objects ->data modelVisit : for regular updatesPython , Character : A-Z,a-zDigits : 0-9 Special symbols : Special symbol available over keyboard White spaces: blank space,tab,carriagereturn,newline, form feedOther characters:-UnicodeVisit : for regular updatesInput and OutputVisit : for regular updatesvar1= Computer Science'var2= Informatics Practices'print(var1,' and ',var2,' )Output :-Computer Science and Informatics Practicesraw_input()Function In Python allows a user to give input to a program from a keyboard but in the form of : raw_input() function is deprecated in Python = int(raw_input( enter your age ))percentage = float(raw_input( enter percentage ))input()Function In Python allows a user to give input to a program from a keyboard but returns the value age = int(input( enter your age ))C = age+2 #will not produce any errorNOTE : input() function always enter string value in Python on need int(),float() function can be used for data , >2:print( Threeisgreaterthantwo!)

2 ") >2:print( Threeisgreaterthantwo!")//indentedsonoer rorVisit : for regular updatesTokenSmallest individual unit in a program is known as Visit : for regular updatesKeywordsReserve word of the compiler/interpreter which can t be used as : for regular updatesandexecnotasfinallyorassertforpas sbreakfromprintclassglobalraisecontinuei freturndefimporttrydelinwhileelifiswithe lselambdayieldexceptIdentifiersA Python identifier is a name used to identify a variable, function, class, module or other object. * An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).* Python does not allow special characters* Identifier must not be a keyword of Python .* Python is a case sensitive Programming ,Rollnumberandrollnumberare two different identifiers in valid identifiers :Mybook, file123, z2td, date_2, _noSome invalid identifier : 2rno,break, ,data-csVisit : for regular updatesIdentifiers-continueSome additional naming names start with an uppercase letter.

3 All other identifiers start with a lowercase an identifier with a single leading underscore indicates that the identifier is an identifier with two leading underscores indicates a strong private the identifier also ends with two trailing underscores, the identifier is a language-defined special : for regular updatesLiteralsLiterals in Python can be defined as number, text, or other data that represent values to be stored in of String Literals in Pythonname = Johni , fname= johny Example of Integer Literals in Python (numeric literal)age = 22 Example of Float Literals in Python (numeric literal)height = of Special Literals in Pythonname = NoneVisit : for regular updatesEscape sequence/Back slash character constantsVisit : for regular updatesEscape SequenceDescription\\Backslash (\)\'Single quote (')\"Double quote (")\aASCII Bell (BEL)\bASCII Backspace (BS)\fASCII Formfeed (FF)\nASCII Linefeed (LF)\rASCII Carriage Return (CR)\tASCII Horizontal Tab (TAB)\vASCII Vertical Tab (VT)\oooCharacter with octal valueooo\xhhCharacter with hex valuehhLiteralsOperatorsOperators can be defined as symbols that are used to perform operations on of Operators 1.

4 Arithmetic Relational Assignment Logical Bitwise Operators6. Membership Operators7. Identity OperatorsVisit : for regular updatesOperators continueVisit : for regular OperatorsArithmeticOperatorsareusedtoper formarithmeticoperationslikeaddition,mul tiplication, +perform addition of two numberx=a+b-perform subtraction of two numberx=a-b/perform division of two numberx=a/b*perform multiplication of two numberx=a*b%Modulus = returns remainderx=a%b//Floor Division = remove digits after the decimal pointx=a//b**Exponent = perform raise to powerx=a**bOperator continueVisit : for regular updatesArithmaticoperator = 5y = 4print('x + y =',x+y)print('x -y =',x-y)print('x * y =',x*y)print('x / y =',x/y)print('x // y =',x//y)print('x ** y =',x**y)OUTPUT('x + y =', 9)('x -y =', 1)('x * y =', 20)('x / y =', 1)('x // y =', 1)('x ** y =', 625) Write a program in Python to calculate the simple interest based on entered amount ,rate and timeOperator continueVisit : for regular updatesArithmaticoperator continue# EMI Calculator program in Pythondefemi_calculator(p, r, t):r = r / (12 * 100) # one month interestt = t * 12 # one month periodemi= (p * r * pow(1 + r, t)) / (pow(1 + r, t) -1)return emi# driver codeprincipal = 10000;rate = 10;time = 2;emi= emi_calculator(principal, rate, time).

5 Print("Monthly EMI is= ", emi)Operator continueVisit : for regular updatesArithmaticoperator continueHow to calculate GSTGST ( Goods and Services Tax ) which is included in netpriceof product for get GST % first need to calculate GST Amount by subtract original cost from Netpriceand then applyGST % formula =(GST_Amount*100) / original_cost# Python3 Program to compute GST from original and net (org_cost, N_price):# return value after calculate GST%return (((N_price-org_cost) * 100) / org_cost);# Driver program to test above functionsorg_cost= 100N_price= 120print("GST = ",end='')print(round(Calculate_GST(org_c ost, N_price)),end='')print("%")* Write a Python program to calculate the standard deviationOperators continueVisit : for regular updates2. Relational Operators/Comparison OperatorRelational Operators are used to compare the to, return true if a equals to ba == b!

6 =Not equal, return true if a is not equals to ba != b>Greater than, return true if a is greater than ba > b>=Greater than or equal to , return true if a is greater than b or a is equals to ba >= b<Less than, return true if a is less than ba < b<=Less than or equal to , return true if a is less than b or a is equals to ba <= bOperator continueVisit : for regular updatesComparison operators = 101y = 121print('x > y is',x>y)print('x < y is',x<y)print('x == y is',x==y)print('x != y is',x!=y)print('x >= y is',x>=y)print('x <= y is',x<=y)Output('x > y is', False)('x < y is', True)('x == y is', False)('x != y is', True)('x >= y is', False)('x <= y is', True)Operators continueVisit : for regular updates3. Assignment OperatorsUsed to assign values to the values from right side operands to left side operanda=b+=Add 2 numbers and assigns the result to left +=b/=Divides 2 numbers and assigns the result to left *=Multiply 2 numbers and assigns the result to left *=b-=Subtracts 2 numbers and assigns the result to left 2 numbers and assigns the result to left floor division on 2 numbers and assigns the result to left **=calculate power on operators and assigns the result to left **=bOperators continueVisit : for regular updates4.

7 Logical OperatorsLogical Operators are used to perform logical operations on the given two variables or (a==30andb==20):print('hello')Output :-helloOperatorsDescriptionExampleandret urn true if both condition are truex and yorreturn true if either or both condition are truex or ynotreverse the conditionnot(a>b)Operators continueVisit : for regular updates6. Membership OperatorsThemembershipoperatorsinPythona reusedtovalidatewhetheravalueisfoundwith inasequencesuchassuchasstrings,lists, = 22list = [22,99,27,31]In_Ans= ainlistNotIn_Ans= anot inlistprint(In_Ans)print(NotIn_Ans)Outpu t :-TrueFalseOperatorsDescriptionExamplein return true if value exists in the sequence, else in listnot inreturn true if value does not exists in the sequence, else not in listOperators continueVisit : for regular updates7.

8 Identity OperatorsIdentity operators in Python compare the memory locations of two = 34b=34if (a is b):print('both a and b has same identity')else:print('a and b has different identity')b=99if (a is b):print('both a and b has same identity')else:print('a and b has different identity')Output :-both a and b has same identitya and b has different identityOperatorsDescriptionExampleisret urns true if two variables point the same object, else falsea is bis notreturns true if two variables point the different object, else falsea is not bOperator continueVisit : for regular , **Exponentiation (raise to the power)~ + -Complement, unary plus,minus(method names for the last two are+@and -@)* / % //Multiply, divide, modulo and floor division+ -Addition and subtraction>> <<Right and left bitwise shift&Bitwise 'AND'td>^ |Bitwise exclusive `OR' and regular `OR'<= < > >=Comparison operators<> == !

9 =Equality operators= %= /= //= -= += *= **=Assignment operatorsis is notIdentity operatorsin not inMembership operatorsnot or andLogical operatorsPunctuatorsVisit : for regular a Python programVisit : for regular updates#function definitioncommentdefkeyArgFunc(empname, emprole): print("EmpName: ", empname) Functionprint("EmpRole: ", emprole) indentationreturn; A = 20expressionprint("Calling in proper sequence") keyArgFunc(empname= "Nick",emprole= "Manager" ) print("Calling in opposite sequence") statementskeyArgFunc(emprole= "Manager",empname= "Nick")A Python program contain the following &n indentationBareboneof a Python programVisit : for regular : -which is evaluated and produce result. (20 + 4) / :-instruction that does = 20 print("Calling in proper sequence") : which is readable for programmer but ignored by Python line comment: Which begins with # line comment (docstring): either write multiple line beginning with # sign or use triple quoted multiple line.

10 This is myfirstpython multiline comment code that has some name and it can be keyArgFuncin above indentation: group of statements is same level create a all 3 statement of keyArgFuncfunctionVariablesVisit : for regular ' Values To Variablename = Python '# String Data Typesum= None # a variable without valuea = 23 # Integerb= # Float sum = a + bprint (sum)Multiple Assignment: assign a single value to many variablesa = b = c = 1 # single value to multiple variablea,b= 1,2 # multiple value to multiple variablea,b= b,a# value of a and b is swapedVariablesVisit : for regular updatesVariable Scope And Lifetime in Python Variable deffun():x=8print(x)fun()print(x)#error will be shown2. Global Variablex = 8deffun():print(x)# Calling variable x inside fun()fun()print(x)# Calling variable x outside fun()Dynamic typingVisit : for regular updatesData type of a variable depend/change upon the value assigned to a variable on each next = 25 # integer typeX = Python # x variable data type change to string on just next lineNow programmer should be aware that not to write like this:Y = X / 5 # error !


Related search queries