0% found this document useful (0 votes)
61 views

Chap 1 - Python Programming - An Introduction

Uploaded by

soft ware
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
61 views

Chap 1 - Python Programming - An Introduction

Uploaded by

soft ware
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 17
PYTHOM PROGRAMMING BY TANEIA 4 KUMAR CHAPTER 1 PYTHON PROGRAMMING: AN INTRODUCTION CHAPTER O} 3 @ 1.1 IDLE ~ An Interpreter for Python @ 1.5 Bitwise Operators @ 1.2 Python Strings @ 1.6 Variables and Assignment Statements @ 1.3 Relational Operators @ 1.7 Keywords @ 1.4 Logical Operators @ 1.8 Script Mode Python is an interactive programming language. Simple syntax of the language makes Python programs easy to read and write. Python was developed by Guido Van Rossum in 199] at the National Research Institute for Mathematics and Computer Science in the Netherlands. Guido Van Rossum named Python by getting inspired from his favourite comedy show Monty Python's Flying Circus. since the language was developed, it is becoming popular day by day amongst the programmers. Various versions of Python have been released til date ranging from version 1.0. This book uses Python 3.6, Python is used in various application areas such as the web, gaming, scientific and numeric computing, text processing, and network programming oP ee Se Tae ia stands for Integrated Development and Learning Environment, ~ >) Python comprises Python shell and Python Editor. While Python Python shell displays shell is an interactive interpreter, Python Editor allows us to work in script the prompt >>> ta ‘mode, While using Python shell, we just need to type Python code at the leat hat tis wait >>> prompt and press the enter key, and the shell will respond with the ‘69 {0" 8 user com- mand Fesult of the computation, For example, when we type >>> printCh “ the taxt to be printod is enclosed betwean and press enter key, Python shell will display: asthe mails 2 tho apostrophe marks are not displayed in the output ‘operator + acts on the ‘operands 18 and 5 operators:+, -» *, 1, Uy %, and ** Python shell window Python Programming hello world Python shell may also be used as a calculator, for example, when we type 18 + 5 followed by enter, Python shell outputs the value of the expression, ic. 23, as shown below: po> 18 + 5 23 In the expression 18 + 5, + is called the operator. The numbers, 18 and 5 on which the operator + is applied, are called the operands. In general, an expression is a valid combination of operators and operands. In Python, all forms of data are called values or objects. For example, 18, 5, and 23 are objects. The expression 18 + 5 yields the value 23. Similarly, the expression 18 - 5 yields the value 13. The expression 18 * 5 yields 90, as Python uses * as the symbol for the multiplication operation. The expression 27 75 yields 5 . 4. Note that the result of division 27 / 5 is real number. In Python, result of division is always a real number. However, if you wish to obtain an integer result (for example, floor(5.4)), Python operator // (two slashes without any intervening blank) can be used. For example, 27 // § yields 5, However, while using the operator //, if at least, one of the two operands is a real number, the result is a real number, for example, the expression 27.0 //_5 yields 5.0. Real numbers are called floating point numbers “in Computer Science terminology in view of the floating point representation used to represent real numbers. However, the number representation is not the subject matter of this book. Python operator & (percentage sign), known as modulus, yields the remainder of the division, for example, 27% 5 yields 2 because on dividing 27 by 5 we get 2 as the remainder. In Fig. 1.1, we illustrate these examples in Python shell. Tie E6t Shel Debug Options Window Help Te pon BE (v3. 61269¢0005, NaF 21 707, 17164052) (HSC v.1900 32 Bie (Harel) Yon wind? 1,02 NeSpyrtohes, ‘oredics™ or “License()" for mare informacion. poets Fig. 1.1. Computation of arithmetic expressions ‘The exponentiation operator (**) yields raise to the power operation, i.e. a>. For example, 3? is expressed as 3 ** 2, and yields the value 9. Python Programming: An Introduction Similarly, 2. ** -1 yields 0.5 as expected. The expressions in each of the examples mentioned above involved only single mathematical operator, but in practice, we would require more complex expressions. Note that whereas the expression 6 / 3 / 2yields1.0(= (6 / 3) / 2), the expression 2 ** 3 ** 2 yields 512 2 ** (3 ** 2)). This so because whereas the operator / (as also +, -, *, //, %) is evaluated left to right, the exponentiation operator is evaluated right to left. We say that the operators, +, -, *, /, //, and %, are left associative operators and the operator ** is right associative. Python operator ~ (negation) yields negative of the operand. For example, 10 * -5 multiplies 10 and ~5 (negative of 5), yielding -50 as a result. Next, we evaluate the foregoing expressions in Python shell: >>> 3 ** 2 9 Boo 6/3 i 2 1.0 >>> 2 ** 3 ee 2D 512 >>> 10 * -5 -50 When we enter the expression 7 + 4 * 3, the system responds with value 19. as a result. Note that in the expression 7 + 4 * 3, Python evaluates the operator * before + as if the input expression was 7 + (4. * 3) because the operator * has higher precedence than +. In Table 1.1, we list the operators in decreasing order of their precedence. The expressions within parentheses are evaluated first; for example, given the expression (7 + 3) * 10 / 5,the system would yield 20.0. Parentheses are often used to improve the readability of an expression. Table 1.1 Precedence of arithmetic operators () (parentheses) “* (exponentiation) z decreasing (negation) pines I (division) // (integer division) * (multiplication) % (modulus) + (addition) - (subtraction) ‘An error occurs when the input expression is not correctly formed, For example, the expression 7 + 3(4 + 5) generates an error because the Operator between 3 and ( is missing: >>> 7 + 3(4 + 5) Traceback (most recent call last): File "", line 1, in left associative oper- atorsi+, =, *, Jy eS right associative oper- ator: ** = operator works as negation operator while the parenthe- ‘ses have the highest Precedence, addition and subtraction are at the lowest level Python complains when it encounters: a wrongly formed expression aan ty a memingess a Pytin sting ray be encksed witia singe, doula, of idle quotes escape sequence \n marks anew ine Python Programming similarly, the expression 7/0 yields a zero division error since division by zemo is 2 meaningless operation. ‘A string is a sequence of characters. To specify a string, we may enclose a sequence of characters between single, double, or triple quotes. Thus, world’, ' "Ajay "', ™, '''today P. ++ are the examples of strings. A string enclosed in single quotes may include double quote marks and vice versa. A str enclosed in triple quotes (also known as docstring. i.e. docume! over several lines, for examp! Note that enclosing quote marks are used only to specify a string, and they do not form part of the string. When we print a string using the print instruction, the value of the string, ie. the sequence of characters within quotes is printed. Also, note that, within a string, \n denotes the beginning of a new line. When a string having \n is printed, everything after \n (excluding \n) is printed on the next line. In this section, we shall study basic operations on strings. Let us begin with the concatenation operator (+). : a nt Introduction Python Programming sed to produce a string by concatenating (wo strings; for example, ye which is the expression "hello ' 4 TEL" yields the string "hello 1!" Similarly, the expression how! 1 are’ 4 ' you?" yields "how are you?’ (@("how! +" are') + * you") as shown below: >>> 'hello ' + ‘hello !!' >>> "how + ' are’ + ' you?! ‘how are you?! The operator * (multiplication) is used to repeat a string a specified number of times; for example, the expression "hello! * 5 yields the string 'hellohellohellohellohello': aor “helio” = 8 *hellohellohellohellohello' ps aN) data yanked ats) Relational operators are used for comparing two expressions and yield True or False. In an expression involving both arithmetic and relational operators, the arithmetic operators have higher precedence than the relational operators. In Table 1.2, we give a list of relational operators Table 1.2 Relational operators (equal to) < (less than) > (greater than) < = (less than or equal to) > = (greater than or equal to) 1 = (not equal to) A relational operator applied on expressions takes the following form: expression expression Thus, the expressions, 23 < 25, 23 != 23, and23 - 2.5 >= 5+ 4, yield Trve, False, and True, respectively. As arithmetic operators have higher precedence than the relational operators, the 5 * 4 is evaluated as if it were (23 - expression 23 - 2.5 >= 2.5) >= (5 strings, strings are » 4), When the relational operators are applied to compared left to right, character by cl acter, based uso of + as the con- catonation operator use of * operator for repeating a string several times relational opera- tors for comparing expression values relational operators 6 ASCII values of chat: actors aro used for ‘tring comparison Python 9 does not allow string values. to be comparad with, pumeric values combining oxpros- sions using logical operators, logical operators not, and, or yield vak ues:True, False Python Programming a Hed ASCH values For example, ASC], and tot =19" fie in the range [65, 90), ee oity. Thus, Tht > TH! yields 197, 122}. and [H8, 57}. respectively. Thus, "h ee ay “i tr as ASCIL value of "ht (= 104) is greater than ASCE VEUE O/B (s 2. ‘Also, thello! > MleLlo! yields True sinee 'h' Is greater than Vt, Similar ‘hit > "hello! yields True eee first charaeter in the two strings is identical and ASCH code o , 1 is greater than ASCII code of to '. Also, if a string is a prefix of another string, the longer string will be considered LOGICAL OPERATORS ‘The logical operators not, and, and ox areapplied to logical operands True and False, also called Boolean values, and yield either True or False. The operator not is a unary operator, i.e. it requires only one operand. The expressions not True andnot False yield False and True, respectively. An expression involving two Boolean operands and the and operator yields True if both the operands are True, and False otherwise, Similarly, an expression involving two Boolean operands and the or operator yields True if'at least one operand is True, and False otherwise. This is shown in Table | “I codes, also ca on their codes of "A! jarger, Table 1.3. not, and, and or operators not ‘True False False True and True False True True False False False False or True False True True True False True False Precedence of logical operators is shown in Table 1,4, Table 1.4 Precedence of logical operators not = Decreasing order or Python Programming: An Introduction While evaluating an expression involving an and operator, the second sub-expression is evaluated only if the first sub-expression yields True. For example, in the expression (10 < 5) and ((5 / 0) < 10), since the first sub-expression (10 < 5) yields False, and thus determines the value of the entire expression as False, Python does not evaluate the second sub-expression. This is called short-circuit evaluation of boolean expression. However, the expression (10 > 5) and ((5 / 0) < 10) yields an error since the first sub-expression yields True, and Python attempts to evaluate the second sub-expression ((5 / 0) < 10) that yields an error because division by zero is an illegal operation: >>> (10 < 5) and ((5 / 0) < 10) False >>> (10 > 5) and ((5 / 0) < 10) Traceback (most recent call last): File "", line 1 (10 > 5) and ((5 / 0) < 10) ZeroDivisionError: division by zero Similarly, while evaluating an expression involving an or operator, the second sub-expression is evaluated only if the first sub-expression yields False. Thus, whereas the expression (10 > 5) or ((5 / 0) < 10) yields True, the expression (10 < 5) or ((5 / 0) < 10) yields an error. To evaluate an expression comprising arithmetic, relational, and logical operators, the operators are applied according to precedence order for the operators given in Table 1.5. For example, the expression not 9 8and7+1 8 or 6 < 4.5 is evaluated as if it were the following equivalent parenthesized expression: ((not (9 == 8)) and ((7 + 1) 8)) or (6 < 4.5) ie. ((not False) and ((7 + 1) != 8)) or (6 < 4.5) (true and ((7 + 1) != 8)) or (6 < 4.5) (True and (8 != 8)) or (6 < 4.5) ie. (True and False) or (6 < 4.5) ie. False or (6 < 4.5) False or False ie. False Table 1.5 Precedence of operators Arithmetic operators Decreasing rators, Relational operat eae Logical operators short-circuit evalu- ation of a boolean expression expressions involving arithmetic, relational, and logical operators expression evaluation using precedence rules bitwise operators operate bit by bit QR - Python Programming EM elas Bitwise operators are the operators that Coe on eee arecied it it it ‘also called bits. In Table 1.6, We list bitwise strings of binary digits 0 and 1, also cal btw operators, their description, along with examples. For the sake of brevity, we assume that all numbers are cight-bit long. Table 1.6 Boolean operators Bitwise Description Example | operator it is if jields 2: Bitwise AND A bit in x & y is 1 if the} 10 & 6 yiel xey corresponding bit in each | 10: 000010 10 of x and y is 1, and 0} 6:00000110 otherwise ~ 2:00000010 BitwiseOR | Abitinx | yis tifatleast|10 | 6 yields 14: xly one of the corresponding | 10: 00001010 bits in x and y is 1, and 0] 6: 00000110 otherwise. oe 14: 00001110 Bitwise Abit in ~x is 1 if and only | ~ 11 yields -12: ‘Complement 11: 00001011 ~x The result obtained from} ~11: 11110100 this operation is -x-1. Note that 111101000 is the * | two's complement of — — 2 12 00001100. 7 Bitwise Abitinx * yistiferactly|10 * 6yields12: Exclusive OR | one of the corresponding |10: 00001010 xy bits in x and y is 1, and0| 6: 00000110 otherwise. : id, 12: 00001100 Left Shift Bits in the binary} 5 << 2 yields 20: x> 2 willyield 1 as the result as x>y representation of x are | shown below: shifted right by y places.|5: 00000101 Leftmost y bits of the result - are filed with sign bit. The }1: 00000001 result obtained from this operation is x/2", Table 1.7 shows precedence order of different operators in Python. Python Programming: An Introduction Table 1.7 Precedence of operators fn fly eh & ee <<, >> She Ko ptas. & AS J” Decreasing . teed order 1.6 VARIABLES AND ASSIGNMENT STATEMENTS Variables provide a means to name values so that they can be used and manipulated later on. Indeed, a program essentially carries out variable manipulations to achieve the desired objective. For example, variables english, maths, and commerce may be used to deal with the marks obtained in these subjects, and the variables totalMarks and percentage may be used to deal with aggregate marks and the overall percentage of marks, respectively. If a student has obtained 57 marks in en this may be expressed in Python using the following statement: >> english = 57 When the above statement is executed, Python associates the variable english with value 57. We can also say that the the variable english is assigned the value 57, or that the variable english refers to value 57. Such a statement that assigns value to a variable is called an assignment statement. In Fig. 1.2, we see that the variable english refers to the value 57. A figure such as Fig, 1.2 is known as reference diagram or state diagram as it shows the current state of the variable. english Y 87 Fig. 1.2. Current state diagram of variable english parentheses have the highest precedence while logical opera- tors have the lowest precedence a variable is a name given to a value assignment state- ment variable english refers to value 57 \ q 10 Python Programming In Python, variables In Python style (often called Pythonic style, or Pythonic way), ‘10 alton. called variables are called names, and an assighntent is called an asoclation op wi binding, ‘Thus, we say that the name eng Lal has been associated with the data object 57, or that the variable eng L Loh has been bound (6 the an ascignmentotato: Gig abject 57, Note that, unlike an expression, on the execution of yy mont binds a vari ; ablo to an object assignment statement, LD LE does not respond with any output, OF course, the value of the variable eng Li sh ean be displayed as follows: >>> english 87 a variable whose value is 57, sign values 64 and 62 to the In the above example, english i Similarly, the following statements will variables maths and commerce, respectively. >>> maths = 64 >>> commerce = 62 ch subject is 100, can be computed c, we assume that maximum mark in ¢ sand overall percentay In this exampl ‘Total marks in these three subj using another sequence of statements Computing overall >>> totalMarks = english + maths + commerce percentago trom >>> percentage = (totalMarks / 300) * 100 marks in different >>> percentage subjects 61.0 ‘ ssigned to variables using an assignment atement. The syntax for assignment statement is as follows: syn, for astm variable = expression _ where expression may yield a value such a an assignment statement, the expression on the ri ide of the equal to operator (=) is evaluated and the value so obtained is assigned to the variable on the left-hand side of the = operator, We have already seen some examples of variables, In general, we must follow the following rules while using the variable numeric, string, or Boolean, In j rules for naming vari- A variable must begin with a letter or _ (underscore character) | ables * A variable may contain any number of letters, digits, or underscore characters, No other character apart from these is allowed. Thus,marks, name, max_marks, _emp, maxMarks, ni, and max_of_3_numbers are valid variables. However, note that the following are not valid variables: total_no. #use of dot (.) 1st_number #begins with a digit Python Programming: An Introduction AmountIn$ #use of dollar symbol ($) Total Amount #Presence of blank between two words It is a good programming practice to make sure that the variables are meaningful as carefully chosen variables make your code readable. For example, to denote the total marks obtained, it is easy to understand what the variable totalMarks represents than a variable a, x, marks or total used for the same purpose. There are several styles of forming variables, for example: total_marks TotalMarks totalMarks TOTAL_MARKS However, one must be consistent in following astyle. In this book, we prefer to use the lowerCamelCase style in which the first letter of every word is capitalized, except the first word which begins with a lowercase letter, for example, totalMarks. While forming variables, it is important to note that Python is case-sensitive. Thus, age and Age are different variables. So, if we assign a value to the variable age and display the value of Age, the system will respond with an error message. >>> age = 24 >>> Age Traceback (most recent call last): File "", line 1, in Age NameError: name 'Age' is not defined Next, let us examine the following statements: >>> aad >>> baa >>> as7 The first statement assigns name a to an integer value 5 as shown in Fig. 1.3(a). The next statement assigns another name b to the same value 5 (Fig, 1.3 (b)). Finally, the third statement assigns a different value 7 to a (Fig. 1.3 (c)). Now the variables a and b refer to different values. > Shorthand Notation By now, we have seen several examples of assignment statements. The following assignment statement updates value of the variable a by adding 5 to the existing value. >asatd 11 always use meaning- ful variable names follow a consistent style in choosing variables Python is case-sen- sitive. age and Age are dif- ferent names more than one vari- able may refer to the same object 4 12 Python Programming ab a > 5 5 7 5 (a) (b) () Fig. 1.3. Current state diagram Alternatively, we can write the above statement as ashorthand notation —> >>> a += 5 ‘Thus, the operator += serves as shorthand notation in assignment statement. Similarly, the statements >>> asatbtic >>> asa ** (b +c) can be written as follows, respectively: >>> a >>> a *m ‘As the shorthand notation works for all binary mathematical operators, a =a b is equivalent to a = b Python also allows multiple assignments in a single statement; for example, the following sequence of three assignment statements >>> msg = ‘Meeting! >>> day = 'Mon' >>> time = '9! may be replaced by a single statement: multiple assignments >>> msg, day, time = 'Meeting', 'Mon', '9' ina single statement ‘Thus, we can specify more variables than one on the left side of an assignment statement, and the corresponding number of expressions, like , , ..., , on the right side. Formally, the syntax for an assignment statement may be described as follows: , , ..., = , , +, Sexprk> Python Programming: An Introduction 13 This notation can be used to enhance the readability of the program. We may also assign a common value to multiple variables, for example, the assignment statement assigning same value to multiple >>> totalMarks = count = 0 < _ _—— variates (n'a olnle statement may be used to replace the following two assignments: >>> totalMarks = 0 >>> count = 0 Suppose we wish to swap values of two variables, say, num and num2. For this purpose, we use a variable temp as follows: >>> numl, num2 = 10, 20 >>> temp = numl >>> numl = num2 >>> num2 = temp >>> print (numl, num2) 20 10 Note that before executing the assignment statement numl = num2 we save the value of the variable num1 in the variable temp, so that the same can be assigned to the variable num2 in the following assignment statement. A variable that is used to hold the value of another variable temporarily is often called temporary variable. Alternatively, we can use the following statement to swap the values of two variables: } >>> numl, num2 = num2, num1 <— 1 KEYWORDS Keywords are the reserved words that are already defined by the Python for specific uses. They cannot be used for any other purpose. Hence, make _K®W0rds have spe- , cial meaning sure that none of the names used in a program should match any of the keywords. The list of the keywords in Python 3.6 is given in Fig. 1.4. False | class | finally | is | return | None continue] for lambda | try True def from | nonlocal| while and del global keywords cannot Sith as ae = . be used for naming not yield objects assert | else | import | pass | break | except in raise elif Fig. 1.4 _List of Python keywords 14 in script mode, Instructions are writ- ton ina file a script should have extension .py oF yw a simple script ‘output on executing the script Python Programming Peels So far, we have done all work using Python shell, an interactive environment of IDLE. The definitions of objects, names, etc., exist only during an IDLE session, When we exit an IDLE session, and start another IDLE, session, we must redo all computations. This is not a convenient mode of operation for most of the computational tasks. Python provides another way of working called script mode. All the instructions necessary for a task are stored in a file often called a source file script, program, source code, or a module, Python requires that such a file must have extension . py or .pyw. To create a script, Python TDLE provides a New Window option inthe File menu, Onclicking the New Window option, a Python Editor window opens, where we can write a sequence of instructions, collectively called a program or a script. A script can be saved using the Save As option in the File menu. It may be executed in shell by selecting Run Module option in the Run_ menu. ‘As a trivial example, the script rea numbers from the user and outputs these numbers. On executing the first line of the script, the system waits for the user to enter a number which is assigned to the variable number1- On executing the second line of the script, the system waits for the user to enter another number which is assigned to the variable number2 . The values of variables number 1 and number? are displayed on executing the third line of the script. dNshow in Fig. 1.5 takes two Fle Edt Format Run Options Window Help [numeri = smpae 0) ~ fpuber? = anput () eine (number, number?) Fle Edt_Shel_ Debug Options Window Help thon 3.6.1 (3. 6.246800@, Was 23 FORT, TTFSAr82) USE ¥900 32 Bie GREAT | Pipe eopyrione, Poreditor or "hicense)* for mare information, a estan: ri /eyenon Prograss/Chapter-1/readtishow.py —meemnnnene || Fig. 1.5 Input-output program __ The problem with the above script is that as we have developed it just now, we remember that the program requires two numbers as the input. However, if we wish to use it a month later, we may forget what inputs are required by the program, and we will need to examine PYTHON PROGRAMMING BY SHEETAL TANGA 4 NAVEEN kumar Python Programming: An Introduction 15 the program again before running it. Surely, we would like to avoid this effort. A good programming practice is to display to the user what data is to be entered. The modified script readNshowWe11 (Fig. 1.6) achieves this by displaying a message to the user as the system waits for user input. Fig. 1.6 Input-output program AN Summary CHAP (|: PYTHON PROGRAMMING * INTRODUCTION . Python interpreter executes one expression (command) at a time. ‘An expression is a valid combination of operators and operands. Operands are the objects on which operators are applied. 3. Arithmetic, relational, logical, and bitwise operators are used for performing computations in a program. 4. A string is a sequence of characters. To specify a string, we may use single, double, or triple quotes. 5. The operator + (addition) applied on two string operands is used for concatenating them. Similarly, the operator * (multiplication) is used to repeat a string a specific number of times. 6. When relational operators are applied on strings, strings are compared left to right character by character according to their ASCII values. 7. While evaluating a Boolean expression involving and operator, the second sub-expression is evaluated only if the first sub-expression yields True. 8. While evaluating an expression involving ox operator, the second sub-expression is evaluated only if the first sub-expression yields False. 9. Precedence order for the operators is as follows: pe 16 10. 12. 13. 14. 15. 16. I7. a Python Programming +H, Ok, ox Nee ie <<, >> a Decreasing order By b is a = b In Python, multiple assignment statements can be specified in a single line as follows: , , ... = , , A keyword is a reserved word that is already defined by Python for a specific use Keywords cannot be used for any other purpose. The list of the Python keywords is given below: False [class finally is return | None continue | for lambda_|[try | True def eu) dl PYTHON PROGRAMMING BY SHEETAL TANGIN + NAVEEN KUMAR. 17 from nonlocal [while fand [aol global not with as Le or yield assert [else import [paso |break | excopt in raise _[eii¢ 18. Python programming can be done in an interactive and script mode. EXERCISES 1. Evaluate the following expressions: (x < y) or (not(z y) and (z < x)) . Evaluate the following expressions involving arithmetic operators: @ -7 * 20+8/16*2+ 54 () 7 ** 2 //9%3 © (7-4*2)* 10/5 ** 2415 @5%10+10-25*8//5 () ' hellot * 2-5 3. Evaluate the following expressions involving relational and logical operators: (a) "hit > 'hello' and 'bye' < ‘Bye’ (b) "hit > 'hello' or 'bye' < ‘Bye’ (©) 7 > 8 or 5 < 6 and 'I am fine’ > 'I am not fine’ (d) 10 != 9 and 29 >= 29 (e) 10 != 9 and 29 >= 29 and 'hi' > 'hello' or 'bye' < 'Bye' and 7 <= 2.5 Evaluate the following expressions involving arithmetic, relational, and logical operators: 4. (a) 5 % 10 + 10 < 50 and 29 >= 29 (b) 7 ** 2 <= 5 // 9 % 3 or "bye' < 'Bye' (c) 5% 10< 10 and- 25>1%* 8 // 5 (7 **2//44+5>80r5 !=6 (ec) 7 / 4 < 6 and 'I am fine' > 'I am not fine' (f) 10 +6%* 2 ** 2 !=9 // 4-3 and 29 >= 29/9 (g) hello! * 5 > ‘hello! or 'bye' < ‘Bye! 5, Evaluate the following expressions involving bitwise operato (a) 15 & 22 (b) 15 | 22 (c) -15 & 22 (d) -15 | 22 (e) “15 (iy ~ (g) ~-20 th) 15 * 22

You might also like