You are on page 1of 325
COMPUTER SCIENCE i ython | Textbook for Class XII * Programming & Computational Thinking * Computer Networks + Data Management (SQL, Django) * Society, Law and Ethics SUMITA ARORA hy 2 - DHANPAT RAI & Co, www.worldvideweb.com Preface Quality of education depends a lot on the curriculum imparted. Since Computer Science is a rapidly evolving field, CBSE constituted a committee to look Into existing Computer Science curriculum and Fecommend a curriculum that is modern, relatively light, teaches timeless concepts like computational thinking, is upto international standards and focuses on problem solving skills than [ust the syntax. The new syllabus of Computer Science (083) Is the outcome of the recommendations by the curriculum review committee. The objectives of this new syllabus are laudable — focus on clear understanding of concepts, applications of concepts, problem solving skills, develop computational thinking etc. This book has been written keeping all this in mind. This book adheres to the CBSE curriculum for Computer Science (083) for Class XI. Based of the syllabus, the book has been divided into four units. Unit 1: Programming and Computational Thinking (PCT-2) Unit 1 has been divided into ten chapters (chapters 1-10). It covers Python programming through fevision tour, Python functions, Libraries, File handling in Python, Recursion in Python functions, Data visualization using PyPlot, Data Structures in Python. This unit also covers basics of determining algorithm efficiency. Unit 2 : Computer Networks (CN) This unit has been divided into two chapters (chapters 11-12). It cavers computer networks’ basics such as types of networks, cloud technology, loT, wired and wireless networks, client, server networks, network devices, modulation techniques, collision in wireless networks, IPv4, IPVG, TCP, other protacals and network tools. Unit 3: Dato Management (DM-2) This unit has been divided into four chapters (chapters 13-16). It covers SQL revision, more on SQL commands, developing a minimal web application using Django web framework, and Python database connectivity with MySQL databases. Unit 4 : Society, Law and Ethics (SLE-2) This unit has been covered in one chapter (chapter 17). It covers many topics and issues related to society, law and ethies, such as 1PR, plagiarism, digital rights and licencing, privacy laws and cyber crime, I act, e-waste management, challenges online and gender and disability issues. Apart from the text book, we have also provided a practical book ‘Progress In Python’ that contains Additional practice exercises, Although the text book contains sufficient number of practice questions ‘and exercises, yet the additional practice of exercises given in the practical book will make the foundation of programming and other concepts even stranger. www.worldvideweb.com Syllabus Distribution of Marks ‘Unit No. Unit Name Marks A Programming and Computational Thinking 2 % 2 Computer Networks 1S 3 Data Management=2 15 : Society, Law and Ethics—2 10 5. Practicals 30 100 Total Unit 1 : Programming ond Computational Thinking (PCT-2) (80 Theory + 70 Practical) 4 Revision of the basies of Python 4 Functions: scope, parameter passing, mutableimmutable properties of data objects, pass arrays to functions, return values, functions using libraries: mathematical, and string functions. ¢+ File handling: open and close a file, read, write, and append toa file, standard input, output and error streams, relative and absolute paths. Using Python libraries: create and import Python libraries 4 Recursion: simple algorithms with recursion: factorial, Fibonacci numbe search, 4 Idea of efficiency: performance defined as inversely proportional to the wall clock time, count the number of operalionsa piece of codeis performing, and meastire the time taken by a program, Example: problem, and understand! how the efficient one takes less time, jecursion on arrays: binary take two different programs for the sar lot: Line chart, pie chart, and bar chart, 4 Data visualization using P 4 Datasstructures: lists, stacks, que Unit 2: Computer Networks (CN) (30 Theory + 10 Practical) + Structure of a network : Types of networks: local area andl wide area (web and intemet), nev technologies such as cloud and lol, public vs private cloud, wired and wireless networks; concept ofa client and server. 4 Network devices such asa NIC, switch, hub, route 4 Network stack: amplitude and frequency modulation, collision in wireless networks, error checking and the notion uf a MAC address, main idea of routing. IP addresses: (v4 and v6), routing table, rouler DNS od wth UBles TCT : basic idea of retransmission, and rate modulation when there iS cont y oad netw tacols: 2 iF " ve a hi {analogy to 2 road network), Protocols: 2G, 3G, 4G, WiFL. What makes a protocol have 2 ? Basi neti tools: traceroute, ping, ipconfig, nslookup, whois, speed-test. 4 Seen ibe HTTP (basic idea), working of email, secure communication : encryplion ef ates (HTTPS), network applications: remote desktop, remote login, HTTP, FTP, SCT 9°" « POPAMAP, SMTP, VolP, NFC. a vi B and access point. www.worldvideweb.com Unit 3: Data Management (DM-2) (20 Theory + 20 Practical) * Write a minimal Django bo and writes the ne BO based web: Mication that parses a GET and POST request, wt elds to a file- Mat file and CSV file et " > Interface , Python with om SQL database, * SQ commands: aggregation unctions having, group by, order by. Unit 4: Society, Law and Ethics (SLe-2) a Se (10 Theory) atellectual property rights, pla i , ly &, Plagiarism, digital rights management, and licensing (Creative Commons, Gotan Auch en we onde pe EM eg + Privacy laws, raud; cyber-crime, i ‘ i rane oe & “ i Cybercrime, phishing, illegal downloads, child Pomography, scams; cyber Technology and society: 2 = nology and society understanding of Societal issues and cultural changes induced by technology. waste management : proper disposal of used electronic gadgets. % Identity theft, unique ids, and biometrics, * Gender and disability ‘ssues while teaching and using computers, PRACTICAL Unit No. Unit Name Marks 1 Lab Test (10 marks) Exthon program (60% logie + 20% documentation + 20% code quality) 7 Small Python program that sends a SQL query to a databsse and 3 displays the result. A stub program ean be provided 2 Report File + Viva (9 marks) Revert file: Minimum 21 Python programs. Out of this at least 4 7 Programs should send SQL commands to a database and retrieve the result; at least I program should implement the web server to write user data to a CSY file, View voce : (based on the report file) 93 3. Project + Viva (11 marks) Project (that uses most of the concepts that have been learnt) 8 Project viva voee 3 Programming in Python 4% Recursively find the factorial of a natural number, Read a file fine by line and print it. 4 Remove all the lines that contain the character ‘a’ in a file and write it to another file, 4 Writea Python function sin (x, n) to calculate the value of sin (x) using its Taylor series expansion up tot terms. Compare the values of sin (x) for different values of 11 with the correct value, + Writea random number or that generates random numbers between 1 and 6 (simulates a dice), + Write a recursive code to find the sum of all elements of a list. + Write a recursive code to compute the 1 Fibonacci number, 4 Write a Python program to implement a stack and queue using a list data-structure, 4 Write a recursive Python program to test if a string is a palindrome or not. vii aa ta plot the function y = * using the pyplot or matplotiib libraries, mi to vrite a Python prone at secepts user inputs, performs some aperation on them, Fee graphical appucation that sromaple, write a small calculator. Use the tkinter ig 84 then Create f Bit pul bn the screen. For © “ weiter OY ian the urllib hbrary. = oe 2 ope error a Joanusing the numpy oF PY — Comput EA io phishing emails and find the most common wor $ Takea sample o + SQL ond Web-Server Delo Managemen! aon ‘and average of the marks in a student marks table + Find the min, m2) . try in the table (customer ID, Sir he tou! number of customers from each country Customer nam eee Oe the (student ID, marks) table in descending order of the marks. ane importing the MySQL module. vith Python by i _ 3 igo a est (POST), and write it to a CSV file, er to parse a user reques ) : 4 Wrte a Django based web server sie something that is tangible and useful. This should be done in i oject is to create Bsa fateaitedoe and should be started by students at least 6 months before the submission groups of 2 to to solve. Students are im here is to find a real world problem that is worthiwhil See foal Mites Gadel ther about the problems that they are facing. Far example, ila business is finding it hard toereate invoices for filing GST elaims, then students can do.a project ta; takes the raw data (list of Iransactions), groups the transactions by category, accounts for the GST tax rates and creates invoiees in the appropriate format, Students can be extremely creative here. They can use a wide variely of Python libraries to ereate user friendly applications such as games, software for and mobile applications. Of caurse to dosome their school, software for their disabled fellow shudent: of this projects some additional leaming is required; this should be encouraged. Students should know how to teach themselves Ifthree people work on a project for 6 months, at least 500 lines af code is expected. The committee has also been made aware about the degree of plagiarism in stich projects. Teachers should take a very strict Jook at this situation, and take very strict disciplinary action against students who are cheating on lib asignments, or projects, oF using pirated software to do the Everything that is proposed ean be achieved using absolutely free, and legitimate open source 7 www.worldvideweb.com www.worldvideweb.com Contents 1 Python Revision ‘Tour 11 Introduction 12 Tokens in Python 121 Keyuveds 2 122 Mentifers (Names) 2 123 LiterateVatues 3 Operators 125 Punctsors 4 13 Barebones of a Python Program 1A. Variablesand Assignments LAI Dynanie Tying 6 142 Multple Assignrents ¢ 15. Simple tnput and Output 1.6 Data Types 17 Mutableand immutabteTypes 1.8 Expressions: 18.1 Eeulusting Arithmetic Operations: 13 18.2 Enchuating Relatonet Expressions 183 Eeulusteng Logical Expressions 1) 184 Tape Casting (Lapltet Type Corsvrsion) 16 185 Muti Library Functions. 16 1.9 Statement Flow Controt 1.10 TheifConditionals 1.10.10 if Cotton Staterzent 19 1.10.2The ifese Comitorsl Stator 20 1.10.3The ssf Conta! Statement 20 110A Nested if Stalerents 1.10 5Storing Condition 141 Looping Statements LILA The for Loy 23 1AL2 The white Loop 2 1.12. Jump Statements break and continue The break Statement 25 The continue Statement 26 1,13 MoreonLoops LAB. Lavp elie Statement 27 1132 Neste Lops 28 a 10 2 4 18 19 2 a a python Revision Tour-II ‘21 Introduction = inython ” irings! , 22 set mS 222 Traversing a String 3 1223 Siring Operators 3S 224 Siring Slices 4 225 siring Functions 42 23 Listsin Python 331 Creating Lists 46 232 Lasis rs Sirings 47 parted 38 233 List Operations 48 2.34 List Manipulation 50 ofa List 51 235 Making True Cory 236 List Functions ST 24 Tuplesin Python 2A Creahing 24.2 Tuples rs Lists 56 243 Tuple Operations 57 244 Tuple Functions and Methods: 59 25. Dictionaries in Python 251 Creating a Dictionary 61 252 Accessing Elements of a Dictomary. 67 253 Characteristics of « Dictionary 254 Dictionary Ope 255 Dictionary Functions and Methats. 65 2.6 Sorting Techniques 26.1 Buble Sort 70 262 Insertion Sort 71 res 55 3 |) Working with Functions 85-140 31 Introduction 32. Understanding Functions 321 Calin 32. 33 Defi ‘wihing/Using a Function 87 2 Python Function Tyres. 85 ning Functions in Python et Structure of a Python Program 9} ow of Execution ina Function Cal} ments ond Parameters. 96 rameters 551 Pestonat Renn quired Atgunsent, 352 Delt Arguments 9g 8 353 Keyed ( 34 35 Passing Pa 55 6 0 85 86 ® Returning Values From Functions 3ST Returning Multiple Valucy 105 37 Composition 3.8 Scope uf Variables S41 Neme Rewlution (Reaeing Scope of a Name) N12 3.9 Mutable/tmmut: ‘able Properties Of Passed Data Objects 291 Mutahdtytmnn Using Python Li 44 tntroduction 42 Whatisatitiary? ily of Arguments Parameters and Funct Calls 7 ny braries Ml - 172 421 Whats a Matute 2 nap 43° Importing Modutes ina Python Peopram AML Urypvting Entire Moule 1 A432 bepwting Select Objects from a Malle 147 $3.3. Pethon’s Preessing of inguit anal 44 Using Python Standard Lib rman 17 y's Functions and Modules Python’ Busitn Functions 442 Working sath Some Stand 45 Creatinga Python Libran 451 Strncture fat in Library Matus 19% age tet 452 Preesture for Creating Packages Io 45.3 Using importing Pyth Libraries 2 le Handling , 173-200 $1 Introduction 52 DataFiles 53 Opening and Closing Files, S31 Opening Piles 1 SAI Ching Iv 1 5A. Readingand Writing Fites 54.1 Reading from Fite S42 Writing onto Files 189 SA} The flash) Function 187 BA Removing Whitespace after Reading from File 18; SAS Significance of File Poanter 1 File Handling 139 Standard Input, Output and E 6 Recursion 6:1 troduction aes 62 Recursive Function 63 Hove Recursion Works fe Recursion in ython fal) Some Rear Cal 215 642 Binary Serch 218 43 Reswiee Bray Seach 222 65 Recursion lteration | | 102 107 107 “41 142 5 173 174 174 v7 190 201 202 205 212 223 7 Idea of Algorithmic Efficiency 5 1 Introduction mena 3 What is Computational Complexity? 73 Estimating Complexity of Algorithms 73.1 Big-O Notatin 234 7.32 Guidelines for Computing Complerity 236 7A_ Best, Average and Worst Case Complexity 8 | Data Visualization using Pyplot 251-295 8.1 Whatis Data VISUALIZATION? 8.2 Using Pyplot of Matplothib Library 8.2.1 Installing and lryynting matplethty 2 8.22 Working with PyPlot Matiets: 253 83 Creating Charts with miatplothb Library's pyplot Interface 83.1 Line Chart 259 832 Rar Chart 265 833 The Pie Chart 225 84 Customizing the Plot 84.1 Anatomy ofa Chart 250 $42 Adting a Tite 231 S43 Setting X and ¥ Labels, Limits and Ticks 281 BAA Adting Legends 285 $45 Socmng a Figure 257 85 Comparing Chart Types 9 Data Structures ~ 1: Linear Lists 297-332 9.1. Introduction 9.2. Elementary Data Representation 93 Different Data Structures DAT Lincar bs 93.2 Stacks 299 933 Queues 299 934 Linked Lists 209 935 Trees 300 94 Operations on Data Structures 95 LnearLists 9.6 Linear List Data Structure Arrays. 299 96.1 Searching ina Linear List 302 26.2 Insertion im a Linear Lis! 304 283 Deletion ofan Element fm a Sorted Linesr List 30 9.64 Traversal of a Lincar List 310 9.65 Sorting a Linear List 311 9.6.6 List Compretiensions 314 97 Nested /Two Dimensional Listsin Python 9.2.1 Tuo Dimensional Lists 320 a+ 233 234 234 239 281 252 259 200 288 297 297 298 300 300 300 319 10 Data Structures ~ I1: Stacks and Queues 333-368-1041 Introduction 102 Stacks 102.1. Implementing Stack in Python 336 1022 Stack Apptications 339 103 Queues 103.1. Implementing Queues in Python 1032 Vantin 2033 Queue Applications 353 11 Computer Networks — 369-386 LI Introduction 112. Computer Networks ~ An Introduction T.21. Compnents ofa Computer Neaork 71 11.3 Types of Networks: HAY Tapesef Netowrts Basel on Ges phic Spread 372 M32. Types of Netivets by Compynent Rates 374 BIAS. Type of Netuvris Bed on Communication Channel 375 114 Network Devices/Hardware ILL NIC (Newest Interface Card) 377 M42 WiFi Card 37 M43 Hub 37 M44 M45. inndge 379 M46 Router 179 MAT Gatesey 379 h ATS MAS Acces Point 179 MS The Cloud IS. Types of Clowls 18 116 Internetof Things (LoT) 116.1 Enabling Technolgies for LOT 11.6.2 Devices that cam form IoT 382 1163 Challenges and Risks 153 12 | Computer Networks - IT 387-430 12.1 Introduction 12.2 Modulation Techniques 122.1 Major Types of Mxtulation 388 13 Collision in Wireless Networks 3.1 Hoa CSMAICA Works 391 12.4 Error Checking (Error Detection) 125 Main Idea of Routing 126 TCP/IP 126.1 Network Congestion and Retransmission in TCP 402 a aii ey 333 334 347 369 370 372 377 381 387 308 390 393 398 401 13 431 - 456 127 Addresseson a Network 127.1 The Domain Name and DNS 408 128 Cellular/Wireless Connectivity Protocols 129 Basic Network Tools 1281 FING 408 1292 TRACEROUTE ifr Linus) or TRACERT (for Wind) 4ir9 1295 NSLOOKUP 407 1294 INONFIG Comment 410 1295 WHOIS Commend 411 1296. Spend Tot at 12.10 Various Protocols Used on Networks 1211 How HTTP Works - A Basic Idea 1212 Working of Email I2I3_ Secure Communication Ane MTTPs air 2 Secure Seles Layer (SSL) 417 1214 Network Applications MySQL SQL Revision Tour 131 Introduction 132, Relational Data Model 133. MySQL-A popular Relational DataBase Management Syst INST MySQL ene SOL sit IN32 Commer MySQL Data Tyres 4 134 Accessing Database in MySQL 135 Creating Tables in MySQL. 136 Inserting Data into Table 137 Making Simple Queries Through Setect Command Seating AME Sctevting Pertcutar Kes 4 lar Cedar 4 Sdeving P Liminating Retertant Data (with beyaved DISTINCD Seeting From All the Roser ~ ALL Reyne 417 Virsang Stracture fe Table 47 Perhorreing Simpte C tomy $8 Ung Coluren Aliser 619 Conditun Based ona Range 438 13720 Conattaon Based om a List $3 INT AT Covtitim awd on Pattern Matches 435 wr, ULL 439 13.8 Creating Tables with SQL Constraints IST SQL Comatracats 440 INS2 Applying Table Constraints 44 Le Searching be 436 40 139 Viewing a Table Structure B40 Inserting Data into Another Table 13.11 Modifying Datain Tables 1312 Deleting Data from Tables 13.13 Altering Tables 13.4 Dropping Tables 13.45. sqLjoins 13.6 Indexes in Database 14 More on sau. AT -AT yy Introduction V2 Ordering Records in Result -Order| ‘by Clause N21 Resting SQL Sct Onder fy Clase 457 Ordering Dato Mutirte Columns 459 Ordering Data on the haves of an Exyrescion $59 N24 Sywerfving Custom Som Onder 460) W43 Aggregate Functions U4 Types ofSQL Functions 145 Grouping Result - GROUP BY HST Noted NS? Ms 153 4. ups ~ HAVING Clause 46) vt Group Lapressions auth GROUP BY 469) 15 Creating a Django based Basie Web Application 477-310 454 introduction 152 Whatis Web Framework? 153, How Web, Websitesand Web-applications Work? 18.4. Introducing Django 155° Installing tan 15.5.1 drstaong Dusngoin Virtual Environment 451 156 Activating Vittual Env Django Basics and Project Structure IST What are Projet and Ap in Django ? $86 1572, Understanding Django Prout Architecture 490 158. Steps toCreatea Basic Django Web Application 15.9 Creating Models, Views and Templates 1581 Creating A 159.2 Creating Templates 433 onment lls 432 1593 Creating Views 434 15.94 Creating URL. Comps 435 15.10 Writing Dictionary Data to CSV and Text Files 15.11. Practically Processing Getand Post Request ee 4a 44s AAS 4S 446 447 a7 448. 457 457 462 465 465 477 477 478 480 480 464 485 oT 492 498 490 16 Interface Python with MySQL S11 - 524 41 Introduction yt 162 Connecting to MySQL fromPython . 1621 Steps for Creating Datatune Connectivity Apptecations 512 163 Parameterised Queries 16.4. Performing InsertandUpdate Queries 17 | Society, Law and Ethics 525-580| 17.1. Introduction 172 Ethical Issues T7221 Intelintual Property Righis 526 1722 Paguram 526 PLE Digi Pnperty Rights 8 173. Open Source Philosophy and Saftware Licences TLL Termintogy 528 1732. Philmophy of Open Swurce 529 1733 Defintaons 539 I134_ Licenses and Domains of Open Source Tehnology 532 Ww 7s 6 17 178 = Ms 17.10 an W742 way Appendix AL-A.18 Privacy Online Froud Gyber Crime Computer Forensics Cyber Law and IT Act ‘Technology and Society 7.91 Eaomomic Benefit E-waste Management I2IO1 EAt¥aste Diyyns! Pravess 540 4 T2102 Refit of eWavte Recuchng 541 entity Theft Gender Issues while Teaching/Using Computers VALI Gender tssues 540 Disability sues while Teaching and Using Computers Appendix A: Utiity of Module's _name_ Appendix 8: Working with A Useful Python Library-Tkinter Appendix C: Django installation on Ubuntu Linux Abpendix D: Creating (data) Models for Djangoapps Appendix E: Insalling MySQL Python Connector Appendix F Project Creationand Distribution ee) su su 510 521 525 526 528 534 534 536 538 538 $39 540 SH 543 545 AL AQ AG AO An ll www.worldvideweb.com Python Revision Tour Tn Wis Charter 22 Introduction 18 Expressions, 12. Tokens in Python 1.9. Statement Flaw Control 1a Barebones of a Python Program 1.10 The if Condonats 24 Vanables and Assignments 111 Looping Statements: 15 Simple tnput and Output 112 Jump Statements — break and continue 16 Data Types 213, More on Loops uW Mutable and immutatte Types. INTRODUCTION You must have enjoyed learning Python in class XL. Python by Guido Vow Rossin in early 1990s, has become a vory popular Programming language among beginners as well as developers. The journey of Python that you started in clase XI will Continue in class XI as wel. In class XI, you shall learn more about Python and somesdvanced concepts, Before we start swith never topics and concepts in Python, We us revise all that you have learnt in class XL. And this chapter will be doing ju take you to the revision tour of Python that you learnt Programming language, developed he sam your previous class. ww.worldvideweb.com COMPUTER SCIENCE WITH PYTHOr _ eT 2 Powis 1.2. TOKENS IN PYTHON The smallest individual unit in a program is known as a Token or a lexical wit. The smallest indeidual unit in | program is tnown at 37 Python has following tokens : ‘nvektcet oc, hen at () Keywords (if) Identifiers (Names) _ (fii) Literals (ip) Operators (0) Punctuators = A sazple Python progran for a1,in range(1)<2 A 4 " punctuators y . ff aX2 =p . beywords teal prints Se keen enters Figure 1.1. Some tobens in a Python program. Let us revise our understanding of tokens. 3 1.2.1. Keywords Keywords are predefined words with special meaning, to the A beyiaeh ite» Wid hn language compiler or interpreter. These are reserved for special meaning reserved by special purpose and must not be used as normal identifier programming language. names. Python programming language contains the following keywords = False assert del for, in or while None break elif from is pass with True lass else. global lambda raise yield and continue except if ronlocal return as def finally impor not try 1.2.2 Identifiers (Names) Identifiers are the names given to different paris of the progearn fanetions, lists, dictionaries and so forth. The naming rules for Python identifiers can be summarized as follows : f © Variable names must only be a nom-keyword word with Po spaces in between. riables, objects, classes, © Variable names must be made up of ip of only letters, tt numbers, and underscore (_, Ce Ee ont lores n ff © Varlble names cannot begin with a number, although Matter an they can contain numbers, The following are some The following are sume invalid identifiers : valid identifiers : DATA-REC contains speaal character - (hyphen) yftte OATES 777 (other than A 7, a+z.and _ (underscore) ) F aoe aS 29cLcT ‘Starting with a digit ork FILEL3, | 4 z1ez9_WT3 1K break reserved heywor ae My.file contains special character dot (.) 1.2.3 LiteralsValues Literals are data items that have a fixed/constant value. Python allows several kinds of literals, which are being given below. (i) String Literals A string literal is « sequence of characters surrounded by quotes (single or double or triple quotes). String literals can either be single line strings or multi-line strings. © Single line strings must terminate in one line 14, the closing quotes should be on the same line as that of the opening, quotes, (See below) © Mult ine strings are strings spread across multiple lines. With single and double quotes, each line other that the concluding line has an end character as \ (backslash) but with triple quotes, no backslash is nevded at the end of intermediate lines. (sce below) : >>> Text = "Hello world? <—___ >>> Text2 © “Hello\ ss Morld* Mattie sing Single line seing Text3="**Hollos Worla!** No fuckatih nerd In strings, you can include non-geap characters through escape sequences. Escape sequences are given in following table : Escape What it does Escope | What it does __ Sequence [Non-graphic character] | __ sequence. __[Nongrophie character) \ | Backslash (\) \e Carriage Retum (CR) v Single quote () \t Horizontal Tab (TAB) uv | Double quate (") Vue Character with 16-bit hex value | xxx (Unicode only) \a ) ASCII Bell (DEL) \Urmxnx, Character with 32-bit hex value | xweeere (Unicode only) \b ASCII Backspace (BS) \v ASCII Vertical Tab (VT) Mt ASCII Formfced (FF) \o00 Character with octal value 000 \n New line character \xhh Character wwith hex value hh. ANiname} | Character named name in the Unicode database (Unicode only) COMPUTER SCIENCE ATH PYTHON — 54 (u) Numeric Literals Numeric literals are numeric values and these can be one of the following types {o) int (signed integers) often called just integers or ints, are positive or negative whole numbers with no decimal point. : The integer literals can be wrilten in : © Decimal form : an integer beginning with digits 1-9. ¢.g., 1234, 4100 etc. {© Octal form : an integer beginning with Oo (zero followed by letter 0) e., 0035, 0677 ete, Here do remember that for Octal, 6 and 9 are invalid digits. mal form : an integer beginning with Ox (zero followed by letter X) eg., 0x73, rs for hexadecimal numbers are 0-9 and © Hexadeci OxAF ete. Here remember that valid digits/ette AF. (b) Floating Point Literals. Floating point literals or real literals floats represent real numbers and are written with a decimal point dividing the integer and fractional parts are numbers having fractional parts, These can be written in fractional form eg. “130, 75, 7. ete, or in Exponent form e., 0.1765, 3.£2, GEM etc. () Complex number literals are of the form a+ bf, where a and bare floats and J (or f) represents JL, which is an imaginary number). «is the real part of the number, and b is the imaginary part. 3 (ii) Boolean Literals ‘A Boolean literal in Python is used to represent one of the two Boolean values i.c., True (Boolean, truc) or False (Boolean false), A Boolean literal can either have value as True or as False. (iv) Special Literal None Python has one special literal, which is None. The None I value. Python can also store literal collections, in the form of tuples and lists ete. | is used to indicate absence of 1.2.4 Operators Operators are tokens that trigger some computation / action when applied to variables and other objects in an expression. ‘The operators can be arithmetic operators (4, -,*, /, %, **, //), bitwise operators (&, °, |), shift operators (<<, >>), identity operators (is, is not), relational operators (>, <, >=, <=, ==, !=), logical operators (and, or), assignment operator (=), membership operators (in, not in), and arithmetic-assignment operators (J, , N=). es, 8h hee, * 1.2.5 Punctuators Purctuators are symbols that are used in programming languages to organize sentence structures, and indicate the rhythm and emphasis of expressions, statements, and program ‘structure. ‘Most common punctuators of Python programming language are : "THVOEIII@, 2.0 = Chop 1+ PYTHON REVISION TOUR . 1,3 BAREBONES OF A PYTHON PROGRAM A Python program may contain various elements such as coniments, statements, expressions ete. Let us talk about the basic structure of a Python program, jf This progean shows a progran’s components ¥ DeFinit ion of function Seevou( ) Follows Commenss & def See¥out) : spin wich @) Print ("Time to say Good Bye 11") + Function Main progean-code follows now a= ass severe _ : be a-10% . , SS erin print (a+3) “ = 3 if bost ® colon means it’s ablock we Print ("Valve of ‘a was more than 15 initially.") Inline comments Sadentetion tovrument Fepaning le indeed tec. ese : nthe nuke of a ine) ‘* print ("Value of ‘a was 15 or less initially.") “+ SeeYou() anton ell — fc 4 cal ling above defined function SeeYou() AS you can see that the above sample program contains various components like : © Expressions, which are any legal combination of symbols that represents a value, © Statements, which are programming instructions, © Comments, which are the additional readable information to clarify the source code, Comments can be single line comments, that start with # and multi-line comments that can be either triple-quoted strings of rmultiple # style comments. © Functions, which are named code-sections and can be reused by specifying theit names (function calls) © Mock(s) or suite(s), which isa y a function. All statements in: up of statements which are part of another statement or He a block or suite are indented at the same level VARIABLES AND ASSIGNMENTS. Variables represent labelled storage locations, whose values can be manipulated during program run. InP le, just assign to its name the value of appropriate type. For example, to create a variable namely Student to hold student’s name and variable age to hold student's age, you just nved to write somewhat similar to what is shown below : Student = "Jacobt Age = 16 hon, to create a var 1.4.1 Dynamic Typing Dynamic Typing vs. Sta! 1.4.2 Multiple Assignments COMPUTER SCIENCE WITH PYTHON a Python will intemally create labels referring to these values as shown belaw, [>-—] ln Python, as you have learnt a variable is defined by assigning to it some value (ofa partculy type such as numeric, string etc). For instaney, alter the statement : X=10 We can say that variable x is referring to a value of integer type. Later in your program, if you reassign a value of some other type to variable x, Python will ot complain (no error will be raised), ¢4 DEST xe10 IIS print(x) A variable pointing to a value of 2 certain type, can be made to X= Hello world” point to a value/object of print(x) Aitferent type. This is called Dynamic Typing. Above code will yield the output as : w Hello world So, you can think of Python variables as labels associated with objects (lit feral values in our ease here) ; with dynamic typing, Python makes a label refer to new value with new assignment (Fig. 1.2). Following figure illustrates it new (Qa) X= “mello worla~ * + +{intsx0 Figure 1.2. Dynamic typing in Python variables Typing Dynamic typing is different (rom Stalic Typing, In Static typing. a data type is altached with a Yariable when it is defined first and itis fixed. That is, data type of a variable cannot be changed in static typing whervas there is no such restriction in dynamic typing, which is supported by Python. Python is very versatile with assignments, Let’s see how. 1. Assigning same value to multiple variables. You can assign same value to multiple variables in a single statement, y.. asbec=1e 1 will assign value 10 to all three variables a, be. i= He values 10 multiple variables. You can even assign multiple values to iables in single statement, ¢: X,Y, 2=10, 26, 30 Chopler 1: PYTHON REVISION TOUR 2 Assigning multipl multiple v; Tt will assign the values order uise, ie, first variable is given first value, second variable the second value and so on. That means, above statement will assign value 10 to x, 20 to Y¥ and 30 to =, Ifyou want to swap values of x and y, you just need to write as follows : May, x In Python, assigning a value to a variable means, variable's label is referring to that value. val=3 val 6 [for statesent val = 3) | Mor statesent 0 | val = 6) val Memory adgress (3000) -Momory adaress [3048} sionng jonng value 3isassigneda value G is assigned a label as bel as val [lor statement val = 6). Val {for statemont val = 3] Now val no longer is referencing to memery locaton 3000, Literal values are having a fixed location and variable ames reference them as labels, Vanable val stores values at same location (memory-address) and changes values stored in it {a) In tradtional programming languages Uke C/C++ etc. i (2) In Python programming language Figure 1.3 Mow vaviables ae stored in traditional programming languages and in Python. 1.5 SIMPLE INPUT AND OUTPUT In Python 3.x, to get input from user interactivel function input ) is used in the following manner : ‘ou can use built-in function input( ). The vortable_to_hold_the_value = input ( You can also combine these two steps in a single step too, « int( input( ) ) Or «varfable_naze> = Float( input( «prompt string>) ) Function int() around input) Converts tha read value into int type and function float) around input) In (20): age = int inputs Wrat ts your ope? 16 function converts the read value into float typo. In [23] outa]: Mo s(eares) AY tyre 2): Ane While inputting integer valucs using int() with input(), make sure that the vi must be int type compatible. Similarly, while inpulting floatin inputt), make sure thal the value being entered must be float be converted to int or float, hence it is not comp. ‘alue being entered 15 point values using float() with ype compatible ( ‘abe’ cannot Output Through print ) Staternent The print ) function of Py ython 3. is a way to send output to st normally a monitor, andard output device, which is ‘The simplified syntax to use print( ) function is as follows : Print(*objects, [ sep=*? op })§ “objects means it can be one or multiple comm: ‘9 separated objvcts to be printed. Let us consider some simple examples first ; print ("hello") #astring print (17.5) # anunber Print (3.14159°(r+n)) E the result of a calculation, which will # be performed by Python and then printed # out (assuming that Some number has been # assigned to chi ri Print (I\’a, 12+5,"years old, ) =n "sultiple comma separated expressions Ee t www.woridvl Chaplet | + PYTHON REVISION TOUR The print statement has a number of features : © it auto-converts the automatically conv first ev lems to strings ic, if you are printing a numeric value, it will ert i into equivalent string and print it ; for numenc expressions, It wales them and then converts thy result to string, before printing. © It inserts spaces between items automatically because the defaull value of sep argurment (separator character) is space’), Consider this code : Four dive anny obs wh mo Print (*Hy*, “nase, "is" att) juve in ther are being print. will print fu the cup ee samy pace ised in FR ne cae rap car a ae ‘You can change the value of separator character with sep argument of print() as per this: The code : Print ("Hy", "mane", "is", *Anit.", sep= will print eee ys sottne 45. .amig, ¢-———— TB im te print agua i tes sae pn ap charter, while © it appends 9 newline character al the end of the line unless you give your own end argument. Consider the code given below : print ("My name is amit.~) print(*I an 16 years old") A print ) function without any value or name or expression My mane is anit. ees 1 an 16 years old Itwill produce output as : Ifyou explicitly givean end argument with a print) function then the print() will print the tine and end it with the string specified with the end argument, and not the newline character, eg. the code print(*Mynane is amit. *, end = “$) print("Lama6yearsold.~) +" will print output as: a tr Mat int) ended he ine with sharaser whi re tad fever hy name is Anit. $1am 1G years Od. newline nxt bie wun rita fry how ial 1.1 Write @ program to input a number and print its cube. nun = float(input( ‘Enter anuaber: *)) fum_cube = nun * num * num print(*The cube of’, num, "is", num_cube) COMPUTER SCIENCE WITH PYTH( PS 10 oto 1.2. Write @ program to Input a number and print its square root. jegam gum = Float (input(‘Enter a nunber: *)) nun_sqrt «nun ** 0.5 print(‘The square root of*, num, "45", num_sqrt) ramon pase nnvrioure? _ Progress In Phan 1.1 ae This ‘Pri session is aimed at revising various concepts you learnt in Class Xl, Please check the practical component-book ~ Progress in Computer Science with Python ond fill thera in PuP 1.1 under Chapter 1 oftor practically doing it on tha computer. popaicee 1.6 DATA TYPES Data types are means to identify type of data and set of valid operations for it, Python offers following built-in core data types : (i) Numbers (x) String (ii) List (ie) Tuple (v) Dictionary, A (i) Dota types for Numbers Python offers following data types lo store and process different types of numeric data : (a) Integers © Integers (signed) © Booleat (b) Floating-Point Numbers (0) Complex Numbers (a) Integers. There are tiv types of integers in Python : (i) Integers (signed). 11 is the normal integer representation of whole numbers. Python 3x provides single data type (inf) lo store any integer, whether big or sual. It is signed representation, i, the integers can be positive as well as negative. (i) Booleans. These represent the truth values False and True, The Boolean type is a sublype of plain integers, and Boolean values False and True behave like the values 0 and 1, respectively. Numbers. In Python, floating point numbers represent machine-level double precision floating point numbers (15 digit precision), The range of these numbers is limited by underlying machine architecture subject to available (virtual) memory. (2 Complex Numbers. Python represents complex numbers in the form A +B j. Complex numbers area composite quantity made of two parts : the real part and the imaginary part, both of Which are represented internally as float values (loaling point numbers). Chopter 1 PYTHON REVISION TOUR You can rel eve the two components ‘Using attribute references. For a complex number real part, © cimag gives the im complex value, Table 1.1. the Range of Python Numbers © areal gives the iginary part asa float, not as a Integers SA unlimited range, subject to available (virkualy memory only | Bouteans tiny _ tues True (1), False (0) Floating point | any untimitet ran rene wy unlimited 1 subject to available (virtual) memory on. unde acting arebitecture. Compter Same as floating point numbers because the real and numbers ian imaginary panty are represented a flaate (il Dota Type for Strings Allstrings in Python 3.x are represent oy i sequences of pure Unico character from every langu: 1s, and 5 characters. Unicade is a system designed to age. A string can hold any type of known characters H characters, of any known scripted language. Following are all legal strings in Python = Se letters, num: “abed” "1234", +g) apy” Valid string Indices ate 0, 1, 2... upto fength-1 In forward direction and =], -2,-3... squence of charoeters and each character —_~ length in backward dection, can be individually accessed using its index. (ii) Lists A Python string isa A List in Python represents a group of comma-separated values of any square brackets eg., following are some lists : (1, 2,3, 4, 5) Ca ] [Neha’, 102, 79.5) datatype between In list too, the values internally are numbered from 0 (zero) onwards ie, first item of the list is internally numbered as 0, second item of the list as 1, 3rd item as 2 and so on. liv) Tuples Tuples are represented as group of comma-separated values of Values of type fist are mutoble any datetype within parentheses, ¢ following aresometuples: Ley changeable — one cn p=(1, 2,3, 4,5) a= (2, 4, 6, 8) COMPUTER SCIENCE WITH PrIFion _ {v) Dictionaries ; / The dictionary is an unordered set of comma parated Key value pais, within (1, eth requirement that within a dictionary, no two Keys can be the same (ley there are unique kaye within a dictionary). For instance, following are some dictionaries : 13,'0:4, U2 5) qari,ter2, 5) poo vowels = (at 1, "e 2,123,704," >>> vowels['a'] “Sik 2 1254 Sat and are the heys of dictionary nnvels; fe nuucs for tise Leys tespetivey Following figure summarizes the core data types of Python. Core Data Types Naber None Seqionces Moopings -— <= | Integer Floating Complex, String Tupie Uist Dictionary I pont, Bootsy 1.7. MUTABLE AND IMMUTABLE TYPES The Python data objects can be broadly categorized into ew = mutable and immutable types, in simple words changeable or modifiable and non-modifiable types. Immutable Types The immutable types are those that can never change their value in place. In Pyt sn int nuondrry, Baas, sings, lupe on, the following types are immutable = In immutable types, the variable names are stored as re you change the value, the variable’s refe explanation for sample code rences to a value-object. Each time ‘nce memory address changes. See following on below 2 Pes qeP res P=10 re? qer © Initially these three statements are executed : p=s . ‘All variates having same vuluerefereice al the amie q 2 4 talae abet Le, pag, #4 al ference same integer re Chopter I: PYTHON REVISION TOUR Each integar value Is an immutable object Figure 1.4 © When the next set of. statements execute, ie, prio re? qer then these variable names are made to point to different integer objects. Figure 2.5, Mutable Types } — Python frontload: some commonly Mulability means that in the same memory address, new used valies. in. memory. Each value can be stored as and when you want. The types that do 28ble referring to that_yalue hot support this propery are immutable types ee See The mutable types are those whose values can be changed in Yariables/identtiers can refer to a e. Only three types are muta s value. Internally Python keeps place. Only three types are mutable in Python. besa inaaledeeoes Thew are : lists, dictionaries and sets. Variables are referring toa value, To change a member of a list, you may write chk = (2, 4, 6] Chk[1] = 40 [twill make the list namely Chk as [2, 40, 6]. 14 COMPUTER SCIENCE Win 1,8 EXPRESSIONS An expression in Python is any valid combination of eperators, literals and wary, expressions in Python can be of any type: aritlimctic expressions, string expressions, peigy eapressions, logical expressions, cumpund expressions ete: — Arithmetic eypressions involve numbers (integers, Meating- eee ithmetic operate An expression in Python Point numbers compler numbers) and arithmetic operators, wie coca ib s . on of E8295 BOWS and atoms. AN csprenige An expression having literals and/or variables of any valid composed of one or re operations type and relational operators is a relational expression, / example, these ane valid relational expressions : mov, yond, Ky zeeqy xeyod, Kewyler ntfor variables af any valid type and logi these are valid! logical expressions : An expression having literals logical expression. For exam al operators is a aorb, bandc, aandnotb, notcernoth Python also provides thwo strin integers, form string expressions operators + and *, when comb wal with string operands and Following are some legal string evpressions : wang™ + “then” would result into ‘andthen' = concatenation 2 vad #2 Fuould result into ‘andand’ = replication 1.8.1 Evaluating Arithmetic Operations Toevaluate an anthmetic expression (with operator and operands), Python follows these rules; © Determines the order of evaluation in an expression considering the aperatar precedence, in the form of © As per the evaluation order, for each of the sub-eypression (ge evalue> coperator ¢y, 13% 3) rally # Evaluate cach of its operands or arguments, # Performs any implicit conversions (¢3, promoting int te float or bool to int for arithmetic on mixed types), Tor implicit conversion rules of Python, read the text given after the rules © Compute its result based on the operator. 4 Replace the subeupression with the computed result and carry an the expression evaluation. Repeat till the final result is obtained. Ina mixed arithmetic expression, Python converts all operands up to the type of the largest operand (type promotion). In the simplest form, an expression is like opt operator op2 (8 aly or p** a). Here, if both arguments are standard numeric types, the following, coercions are applied : : . = © I cither argument is a complex number, the other is converted to comple ; ‘hn implicit tyne conversion is 2 © Otherwise, if cither argument is a floating point Eenversion performed by he number, the other is converted to floating point ; pe, ipa ee © No conversion if both operands are integers. Chopler I: PYTHON REVISION TOUR Table operator precedence [Operator at Description 0 Parentheses (grouping) phat + Exponentiation “ Bisse nor Vositive, negative (unary +.) Muluplication, division, floor division, remainder te Addition, subtraction, & Bitwise AND ” Hitwise NOR 1 Ditwise OR stra pesca, Comparisons (Relational operators), identity operators notre Boolean NOT. and | Bowlean AND. or Boolean OR tans Example 11 Consider blow soem expressions what, What elf be te fn result and final data type ? (@) a, b= 3,6 h) a, b=3,6 (c) a, b=3, 6.0 eabla cabifa c=bxa Ans. (a) In expression 26/3 bya ©-2.0 | I dnt int LH rataris / which abvesy Ht rout floating pt (b) In expression (©) Inexpression c=6//3 ob Wa €=6.0%3 b X a cn2 | | I | int int float int CH = int float 1.8.2. Evelvoting Relotional Expressions All comparison operations in Python have the same priority, which is lower than that of any arithmetic operations. All relationalexpressions (comparisons) yield Boolean values only ie True or Fatse. Further, chained expressions like aq) and (qe y) (ii) (aes N) and (N<= 1) 1.8.3 Evaluating Logical Expressions While evaluating logical expressions, Python follows these rules : ical operators is lower than the arithmetic operators, so consti (i) The precedence of ke arithmetic sub-expres: applied, eg, 25/5 0r 2.0 + 20/10 So, the overall result will be 5. be first evaluated as; 5 0r 4.8 (ii) The precedence of logical operators among themselves is not, and, oF. So, the expression 2 or band not ¢ will by evaluated as : Similarly, following expression (aor (Dard (2086) )) and gor nol rill be evaluated as: ((p and q) or (nat 9) (i) Important. While evaluating, Python minimizes intemal work by following these rules : (2) In or evaluation, Python only evaluates the seco argument if the first one is false jay (6) Inand evaluation, Python only evaluates the second argument if the first one is trey Example 13. What will be the output of fol (5.619) and (185) of (3 ¢ 18) and not 818 Solution. False ing expression ? 1.8.4 Type Costing (Explici Aneaplicit type cunversion is user-defined conversion thal forces an expression tobe of specific type. The explicit type conversion is also known as Type Casting. Type Conversion) Type casting in Python is performed by type>( ) function of appropriate data type, in the following manner : (expression) where is the data type to which you want to Ci type-cast your expression. smversi The exzlicit conversion of an For exomple, if we have (a = 3 and b = 5.0), then operand ta a specific type Is int (b) called type casting. will cast the data-type of the expression as int. 1.8.5 Math Library Functions Python’s standard library providesa module namely math for math related functions that work with all number types except for complex numbers. topless PYTHON REVISION TOUR In order to work wath functions of math module, you need to first import ito your program: by giving statement as follows as the top line of your Python script : Amport math Then you can use math hbrary’s functions as math. « Table 1.2. Some Mathematical Functions in math Module Description Example fs. Funetle Prototype No. 2"| (General Form) 1. [eet [math ceit(num sqrt | mathsqrt (numy 3. [op — | mathexprany 4. [fabs | mathfaus (num 5. | floor | math floor (rum) 6. [log | mathutog (num, [base] 7. [toga | math togto (num) Ps. | pow — | mathpow (base, exp) 9. mare) 10, | cos | mathcos(arg) Te Jtan | math.tan(arg) math degrees(2) mathradiandz) | The cell) function reiums the Somalia integer et fess than mm, The sqrt( ) function returns the square root of num. If num <0, lomain error occurs ‘The expt) function retums the natural logonitlun e raised to the arg power | The fabs() funchon returns the absolute value uf nam, ‘The floor ) function returns the Iargest integer not yeeater than ‘The Hoge} function returns the natural logarithm for mum, A domain ertor occurs if rune is egalive and a range error eceurs if the argument nun is zero, The Tog) function returns 2-10 Logarithm for mum A domain error occurs if num ts and a range error if the argument is zero. pow! P unction returns base raised to ey power fey. bse ery A domain error occurs if buse =O) and exp <=0; oso if fae cand caps nat integer The sin( ) function setums the sine of arg. The value of arg must Le in radians The cos ) function returns the cosine of arg. The value of ary must be in radians, The tant ) function returns the tangent of arg. The value of arg must be in radians, The degreest } converts angle x from radions to degrees. ‘The radians() converts angle x math.ccil(1.03) gives 20 math cil(-103) gives “10 math sqrt(81.0) gives 9.0. ‘mathexp(20) gives the value of A. math fabs(1.0) gives 1.0 math fabs(-10) gives LO math floor (1.03) gives 1.0 math loor(-103) gives -20. math Iog(1.0) gives the natural logarithm for 10, math Jog(1024, 2) will give ogarith of 1024 to the base 2, math Jog10(1.0) paves base 10 logarithm for 1.0, math.pow 3.0, 0) ° math pow (10, 2.0) gives value of es value of mathsin(val) (til is a number) matheos(val) (ou! is a number). math tan(val) (val is a number) mathdegrees (3.14) would give wa math radians (179.91) would from degrees to radians. give 314 w.worldvideweb.com COMPUTER SCIENCE vaTH pry )~ =, DATA HANDLING Proaress ln Prhen 4 This ‘Pril” session Is aimed at revising various concepts you learnt in Class XI. Science with Python and fill it there in PrP 1.2 under Chapter | ofter practically doing « on the computer. é Please check the practical component-book - Progress in Computer ) portrace LeT Us REVISE Ss & A Python program can contwin vurious components like expressions, statements, comments, functions, blocks ang indentation. Blocks ore represented through indentation, Prnton suppers dynamic ting ie. @ variable con hold values of different ‘ypes of different times, The taped) is used to ebtorn op from user 5 always terurm 0 ting pe of value Output ts generated through print } (by culling print function) statement. Operators are the symbols (or keywords sometimes) that represent specific © Merpreasion s composed ef one or more operations. tsa ulid combination Types of operotors used in on en arithmetic expression. pperations. ooo oeoes of operctors, Inerals and variables, Presson deiermine its type. For instance, use of arithmetic operators mates t Expressions con be arithmetic, relational wr logical, compound ete In tnpicit conversion, all eperands are comerted up tothe type Of the largest operand, which is called ype Promotion or coercion The explicit conversion of an operand to a specific ype is called type casting and it is done usin functions that is used as <*9P6 conversion function » ( cexpression>) oe pe conversion 1.9 STATEMENT FLOW CONTROL In 2 program, statements may be executed sequent Program ally. selectively or iteratively. Every 6 language provides constructs to support Sequence, selection or iteration. Acenditional isa statement w 9 statement set which 1. Compound Statement A compound statement re r of statements executed as a unit. The ‘compound Statements of Python are written in a specie Pattern as shown below : set which is executed, on th basis of result of a condition. A loopis 's executed repvatedly, until the end condition is satistied, “Compound statenent header > ; «indented body containing Sultiple simple and/or ‘Compound statenents> Y= PYINON RLVIION TOUR osonr | ‘The conditionals and the loops are compound statements, ic, they contain other statements, For all compound statements, following points hold : © The contained statements are not written in the same column as the control statement rather they are indented to the right and together they are called a block. © The first line of compound statement, i, ils header contains a colon () at the end of t- For example : unl = int(input ("Enter numberi")) nun « Ant (Input ("Enter number") Af mud «rund 2 ¢————— The eu (4) ne rdf ener on reset 8 compe Hemet t= num2 * nun2 tetele the cosines staterens wuhin fore leaders othe night print(num2, num, t) 2. Simple Stotement Compound statements are made of simple statements, Any single executable statement is a simple statement in Python, 3. Empty Stotement The simplest stateinent is the emply statement j,, a statement which does nothing. In Python an empty statement is the pass statement. It takes the following form : pass Wherever Python encounters a pass statement, Python does nothing and moves to next statement in the flow of control 1.10 THE IF CONDITIONALS The if conditionals of Python come in multiple forms : plain if conditional, if-else conditional and if-elif conditionals. 1.10.1 Plain if Conditional Statement An if statement tests a particular condition; if the condition evaluates to Irie, a course-of-oction is followed ic. a statement or set-ol-statements is exccuted, If the condition is filse, it does nothing : The syntax (general form) of the if statement is as shown below : 4€ ccondittonal expression» statement [statements]

You might also like