0% found this document useful (0 votes)
3 views16 pages

Chapter 02

Ip pdf class 11

Uploaded by

sanganidivy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Chapter 02

Ip pdf class 11

Uploaded by

sanganidivy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Getting Started with Python 2.1 INTRODUCTION A computer is a versatile machine that can execute millions of instructions in a second but can neither think nor make any decisions on its own. It requires a program to be written to instruct what needs to be done. A program is a set of instructions written in a sequence that guides the computer to perform a particular task. Irrespective of the language being used, the first and foremost thing to be done while writing a program is to understand the problem well, analyze it and try to solve it ina logical manner. The process of writing a program is called ‘programming. Thus, while writing a program, we need to clearly understand the problem and its solution, otherwise we will end up writing incorrect or inefficient codes. Fig. 2.1: Computer Programming Writing correct codes/instructions in a proper sequence and in the right context is extremely important. This is where computational thinking comes into play. Therefore, before the actual coding starts for solving a problem, the ways in which it could be resolved must be understood. Fig. 2.2: Computational Thinking Programming languages have been developed to meet the needs of programmers and users. They are an effective tool to develop applications that positively impact the working of an organization, economy and society by increasing productivity and improving efficiency. Languages die and become obsolete when they fall short of expectations of the users and programmers and are consequently replaced and superseded by some more powerful languages. However, Python is a programming language that has stood the test of time and remained relevant across industries and businesses, among programmers and users. 2.2 PYTHON PROGRAMMING LANGUAGE When we encounter the word python, it reminds us of a flexible reptile. However, the programming language has been named ‘Python’ because just as the reptile has a flexible body, the language too is easy, simple and highly flexible. ww Python is an open-source, object-oriented, ol python high-level programming language. It was developed by Guido van Rossum in 1991 at the National Research Institute for Mathematics and Computer Science, the Netherlands. Python is based on ABC language, a teaching language created to replace the programming language BASIC, which was developed earlier. Python has been developed using C language. Guido van Rossum Python is a general-purpose programming language that can be used effectively to build any kind of program that does not require direct access to the computer's hardware, Python is used by Google search engine, YouTube, Netilix, Spotify, Dropbox, Instagram, etc. It is being widely used for system programming, GUI programming, internet scripting, web gaming, text processing, network programming, commercial robots, and in space and scientific applications. CTM: Python is based on ABC language and was inspired by the famous BBC comedy show Monty Python's Flying Circus. 2.2.1 Features of Python Python is an interactive, interpreted language with a simple syntax. It is becoming increasingly popular owing to its various features, which are as follows: 1. Python is an interpreted, interactive, directly executed language with a pre-compiled code. This means that it is processed at runtime by the interpreter and we need not compile our program before executing it. 2. Itisa dynamically typed object-oriented programming language with few keywords (reserved words) and simple English-like structure, which makes it easy to learn. Itisa free, open-source and portable language having a large repository of libraries 4. Ittakes less time to develop, as Python programs are typically 3-5 times shorter than the other programming languages. This is because of its built-in, high-level data types and its dynamic typing 5. It is extensible and highly efficient as there is no wastage of time in declaring the types of variables or arguments. wT Informatics Practices with Python-X| —. 6. Itsupports GUI (Graphical User Interface) and an optimized garbage collection mechanism for better memory management. 7. Itis easily compatible with other languages like C, C++, Core Java, etc. 8. Python is used for both scientific and non-scientific programming. kos 9 large Standard Cart 2 ovj Dynamically} 1d Oriented Typed Fig. 2.3: Features of Python 2.3 ADVANTAGES OF PYTHON Apart from the given features, Python offers the following advantages: 1. Platform-Independent: Python is platform-independent and can run across different platforms such as Windows, Linux/Unix, macOS, etc. Thus, we can say that it is a portable language. 2. Readability: Python programs use clear, simple, concise and English-like instructions that are easy to read and comprehend even by non-programmers or people with no substantial programming background. Object-Oriented Programming Language: It is an interactive, interpreted and dynamically typed object-oriented programming language 4. Higher Productivity: Since Python is a simple language with small codes and extensive libraries, it offers higher productivity to programmers as compared to languages like C++ and Java. In other words, we write less and get more done. Less Learning Time: Because of simple and short codes, less time is required to understand and learn Python programming. 6. GUI Programming: Python supports GUI applications that can be created and ported to many system calls, libraries and Windows systems such as Windows MFC (Microsoft Foundation Class Library), Macintosh and the X Window System of UNIX. 7. Ample Availability of Libraries: built-in modules to solve a task, It provides large standard libraries with numerous 8. Syntax Highlighting: It distinguishes between input, output and error messages displaying them with different color codes. (611110 Started with Python XB. 2.4 LIMITATIONS OF PYTHON Agart from the several advantages that Python offers, which makes it one of the most popular programming languages, it has the following limitations: 1. Speed: Python is slower than C and C++. However, Python is a high-level language and, unlike Cor C+4, does not directly interact with the hardware. 2. Mobile Development: Python is not considered a good language for mobile development. Itis seen as a weak language for mobile computing. This is the reason why very few mobile applications are built using it. 3. Memory Consumption: Python is not a good choice for memory-intensive tasks. Due to the flexibility of data types, Python's memory consumption is also high. 4, Database Access: As compared to popular technologies like JDBC (Java Database Connectivity) and ODBC (Open Database Connectivity), Python's database access layer is found to be a bit underdeveloped and primitive. Thus, it cannot be applied in enterprises that need smooth interaction of complex legacy data. 5. Runtime Errors: Python programmers have cited several issues with the design of the language. Since the language is dynamically typed, it requires more testing and has errors that only show up at runtime. 2.5 INSTALLING PYTHON Ever since Python language was first developed, it is gradually becoming popular among Programmers. Several versions of Python have been released since then, beginning with Python 1.0. ‘We shall be working on Python 3.6.5. However, any 3.x version can be used to implement Python programming concepts. Before we start, make sure Python is installed on the system. To install Python, first download the installation package of the required version from the following link: heeps://[Link]/downloads/ For installation details, scan the given QR code. f This Python distribution comes with Python IDLE, Python interpreter and pip (Preferred Installer Program/Package Installer for Python), 2.6 INTERACTING WITH PYTHON (PYTHON IDLE) Python is a flexible, dynamic and powerful language that can be used in different ways. It can be interactively used simply to test a code or a statement line by line or while exploring its interface. To write and run Python programs interactively, we can either use the command line window or IDLE, which is a simple Integrated Development and Learning Environment that comes with Python. The most important feature of IDLE is that it is a program that allows the user to edit, run, browse and debug a Python program from a single interface. ww Informatics Practices with Python! 2.6.1 Python Shell When we launch Python IDLE by clicking its icon on the desktop or selecting it from START menu -> Apps by name — IDLE (Python 3.6 32-bit), it always opens in the Shell 4 Fig. 2.4: Starting Python Shell n Shell is an interactive window where we can type a Python code and see the output in me window. It is an interface between Python commands and the OS. CT™: The interactive interpreter of Python is termed as Python Shell IDLE comprises two working modes: Python Shell (Interactive mode) and Python tor (Script mode) as shown in the following figure. 5 Pytnon 365 She = oes 43.6.5 (v3.6.5:£59¢0932b¢, Mar 28 2018, 16:07:46) [MSC v.19 bit (Intel}} ‘on win32 = "copyright", "credits" or “license()" for more inf a ‘Unites , . °c sting Started with Python oN On opening, Python shell shows a welcome message displaying its version and a copyright notice. After this, the command prompt (>>>) followed by a blinking cursor gets displayed, which indicates that IDLE is now ready to take Python commands from the user (Fig. 2.5). Fie dt Shel Deg Optens Window Help Python 3.6.5 (v3.6.5:£59¢0932b4, Nar 28 201 00 32 bit (Intel)} on win32 ‘type "copyright", “credits” or “license()" for more information. — >>> | Start typing here Fig, 2.5: Interactive Python Shell Learning Tip: Python shell displays the prompt >>> to indicate that it is waiting for a user command to be entered. This is Python Shell, which is part of Python’s Integrated Development Environment. The three greater than signs (>>>) are called prompt or Python command prompt. 2.6.2 Command Line Interaction When commands are entered directly in IDLE from the keyboard, the Interpreter/IDLE is said to be in Interactive mode. In Interactive mode, type the command “Hello World” after the prompt (>>>) and press Enter. Our First Program Now we begin with our first command in Python Interactive mode, as shown below. Practical Implementation-1 Fiat _Seat_Ociey Options Window lp _ _ python 3.6.5 (v3.6.5:£59¢0932b4, Mar 28 2018, 16:0 00 32 bit (rntel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> "Hello World” 6) (MSC v.19 ‘Hello World" >> ‘As soon as we press Enter after typing the first statement, it gets executed immediately, i. the output is displayed in the Shell simultaneously. — Informatics Practices with YOO Alternatively, this can be done using print() function as shown below. le Eat Sheng Opens Window Help Python 3.6.5 (v3.6.5:£59c0932b4, Mar 28 2018, 16:07:46) ~ (Sc v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or “license()" for more info rmation. >>> print ("Hello World") Hello World >>> print ("Welcome to python Programming") Welcome to Python Programming >>> ery Example of multiple statements >>> print (10); print (20) 10 20 ‘Multiple statements typed are executed’ immediately and splays the output. This method of typing the message after the prompt (>>>) is termed as Displaying. In the above example, we have given two print() statements for displaying two different messages. Ithas now become evident that we can give commands at the primary prompt and see immediate results. print() is a function which is used to display the specified content on the screen. The content (called argument) is specified within parentheses. print() statement without any arguments will simply jump to the next line. Python is a case-sensitive language. This means that Python differentiates between uppercase and lowercase letters. For example, Print (P capital) and print (p small) are two different things for Python. While print() is a built-in method in Python, Print is just a word and not a command or method. This can be observed by typing the command Print("Hello World"). Python will not be able to interpret it and will show error, as shown below. Dy stew at eel Soret serene eererenr {isc v.1300 32 bit (ntel)} on win32 Type “copyright, "credits" or "license()* for more info srmation. | >>> print ("Hlell0 World") a Hello World >>> print ("Welcome to Python Programing") [Welcome to Python Programming >>> Print ("iiello World”) ftraceback (most recent call ast): File "", line 1, in While using print() method, the message or argument to be displayed must be placed within quotation marks (single ‘’ or double “*); only then, the argument is displayed as it is. If the argument is not placed within quotation marks, then the interpreter tries to evaluate the argument and displays the result, This feature is used to perform calculations. If we give an arithmetic expression as an argument, the interpreter shows its value, as shown in Practical Implementation-; ee Getting Started with Python Sz Practical Implementation-2 We can also perform mathematical calculations using the Python command prompt, just like we have done with text/string messages in IDLE. 3.6.5 (v3. 900 32 bit (rate: }nype “copyright™, "credits" or "1icense()* for more information. poo s+ 8 1B >>> print (a0 + $8) a ‘As shown in the given code window, we have performed mathematical calculations using print() function and by directly typing the command without the use of print() command. In either case, these statements are immediately executed by the Python interpreter and the output is displayed within a fraction of a second. Note: print() function will convert the argument or message into a string before displaying it on the screen. n. When print() function is executed, the values of consecutive arguments are separated by space between them. So, we can say that space is the default separator of values in the output. We can also specify some other string as the separator using sep argument of print() function (Fig. 2.6). Its syntax is: print(value, sep=' ', end='\n', file=[Link]) value: Values to be printed, which can be any message or variable sep: Separator inserted between values, by default, a space end: String appended after the last value, by default, a new line file: It is optional. By default, file attribute is used to print objects on the screen, “4900"92 bit intel) on vine laype “copyrignt™, "credits" or “License()* for more informatio > pea 30, 20,20). pace the dete separator >>> print (10,20,30,sepe"\e 3) io a8 ae Fig. 2.6: Use of sep argument with print() method. wy Informatics Practices with Python-XI If we use sep argument to specify the separator, then it must be specified after all the values to be printed. Otherwise, the interpreter shows a syntax error. For example: +", 40) Syntax Error 1 argument follows keyword argumen| >>> print (10,20, 30, sep Syntax Error: positi TM: In Python command-line or interactive mode, an extra space between the Python prompt (>>>) and the command will produce a syntax error. end Parameter with print() Python's print() function comes with a parameter /argument called ‘end’. By default, the value of this parameter is ‘\n, ie., new-line character. We can end a print() command with any character/ string using this parameter. print() function uses sep parameter to separate the arguments and ends after the last argument. For example, type the statement >>> print ('cow', 'cat', 'dog', sep=', ', end="!!!\n") using end parameter with the print() function and press Enter. Python Shell will execute it and display the output as shown below (Fig. 2.7). Fig. 2.7: Use of end parameter with print() method. More about Python Shell Python Shell Window (Fig. 2.8(a)) comprises menus (File, Edit, etc.) and a Python command prompt (>>>) where we can type or enter statements or expressions to be executed. It is quite different from others in the way that it allows to scroll back to previous commands, to cut, copy and paste earlier commands/statements and to modify them. Python Shell window has the following menu options: File menu contains options such as New File, Open, Open Module, Recent Files, Module Browser, Path Browser, Save, Save As, Print Window, Close and Exit. Edit menu allows us to edit the text we type in the Shell by applying various editing options such as Undo, Redo, Select All, Cut, Copy, Paste, Find, Replace, etc. Shell and Debug menus are useful when creating larger programs. Shell menu allows us to restart the Shell or search the Shells log to trace the most recent reset. Debug menu provides useful menu items for debugging a Python program in order to trace errors while checking for line-by-line execution of the entered Python statements. Options menu allows the user to configure IDLE according to the suitability and working requirements, eg., changing font style of Python Shell window, highlighting code color, shortcut keys, etc. Window menu allows the user to rearrange windows and select the active window. Getting Started with Python —_x Help option provides Python help and documentation. 2.6.3 Python Editor Window (Working in Script Mode) Till now, we were working with the Interactive mode, wherein there is no provision for holding or saving commands typed at the Python prompt. All these commands, along with their output, get cleared as soon as we close Shell window. This limitation can be overcome by working in Python script mode wherein we can save the commands we are typing, This switchover is carried out through the Python Shell itself. Script mode enables us to write a block of code or multiple lines of code, known as a script or Python program. The script is saved with .py extension Working with Python script mode involves the following steps: Step 1: Create Script/Program File File menu provides various options to create a new file, open an existing file, open a module, save the current module/session. When you click on New File option (Fig. 2.8(a)), a new window opens, ie, the Python script mode or Python editor window, which is a simple and standard text editor where we can type or edit our code. At the time of its opening, this file window is named ‘Untitled’ by default, as shown in Fig. 2.8(b). The name can be changed by the user by saving the file. oy Soe = (@5-6.5:f58c0930b4, Mar 20 2018, 16:07 1900 32 bit (intel) on wins , Neeeaits” oF “License ()* for more Fig. 2.8(a): Selecting File > New File from Python Shell Fig, 2.8(b): Python Editor (Script Mode) Opens Step 1(a): Our next step is to type some commands in the blank file, as shown in Fig. 2.8(c), and save this file by clicking on File -> Save As option (Fig. 2.8 (d)), followed by typing a proper name for it instead of the default name ‘Untitled’, as shown in Fig, 2.8(e). ie tat fom fe Cot Yan pein ("this is ny first program PEAne("Using Python Script mode") ‘avantageous over Tateractive mode") wes the Statements typed using this mode") eine ("1 ‘This method of typing the ‘commands using print) statement Is termed as Fig. 2.8{(c}: Type the Commands in New Blank File (Script Mode) io a Informatics Practices With PYLON 9 secon Perna Fig. 2.8(@): Save File with extension py Even if we forget the extension .py or .pyw while saving a file for the first time, the Python IDLE automatically gives it along with the file name. acho) writing the code program using script mode, the 2 by line and then produces the output on the interpreter takes the whole program, debugs ell. en Step 2: Run Script/Program File ‘To execute a Python Script file, choose Run Module option from Run menu or press the function kev F5 (Fig. 2.8(f)). The output of the Python program shall be displayed in the Python Shell window, as shown in Fig. 2.8(g). Fig. 2.8(f): Running the File ut Script Mode working in the Script mode, when we enter the statements to be executed and press we do not automatically see the results the way we do in the Interactive mode. To see it from a Script mode, we have to run this script and/or invoke print() function. Getting Started with Python —~_ see1) on ving “credits” or *license()* for more infor [Using Python Script mode Tt is advantageous over Interactive mode Te saves the statements typed using this mode Fig, 2.8(g): Output of the program displayed in Python Shell Remember, that even if we enter print() statements in the Script mode, the output shall be displayed only in Python Shell. 2.7 EXITING PYTHON In order to exit Python command prompt, press the shortcut key com! quit() or exit() built-in function and press Enter. ation Ctrl + Q or type We can also use the shortcut key combination Alt + F4. Coiachonen) If exit() or quit() function do not import sys? sy! emony BYTES > Asset of instructions written using a programming language is termed as Program/Code/Program Code. > Python uses concise and easy-to-learn syntax, which enables programmers to write more codes and develop more ‘complex programs in less time, > Python was developed by Guido van Rossum in 1991. > Python interpreter executes one statement (command) at a time. > Python provides two different ways to work with—Interactive mode and Script mode, > In interactive mode, commands are not stored as a program. Instead, as soon as you press Enter after typing @ command, the output is shown right away, appearing between the commands. Interactive mode is suitable for testing codes. > Python is a case-sensitive language. Thus, Ram and ram are considered different identifiers in Python. > Python's interactive interpreter is also called Python Shell > Python editors automatically indent statements. print) statement outputs an entire (complete) line and then goes to the next line for subsequent output(s) Script mode is useful for creating programs and then running them later and getting complete output. > All programs in Python are saved with .py or .pyw extension, = pei OBJECTIVE TYPE QUESTIONS + 1, Fill in the blanks. (a) The method of typing the message after prompt (>>>) is termed as : (b) Python IDLE comprises... mode and oo... mode. AF tovrnati Practices with Pt C function in Python is used for outputting text to the console. {d) To execute a Python script file, choose option from menu. (e) The interactive interpreter of Python is termed as Python (f) Python program files have e extension and are also known as (g) By default, Python scripts are saved in the Python folder. (h) In script mode, the program's output always appears on ia (i) By default, the value of Parameter is “\n’ ie., the new line character, 2, State whether the following statements are True or False, (a) Python consumes more memory due to the flexibility of data types. (b) Indentation does not matter in Python programming, (c) Python is seen as a weak language for mobile computing. (a) In Python, two variables with the same name but different letter cases, e.g., uppercase and lowercase, are treated as different identifiers. (e) Python Interpreter converts all code into machine language at once. (f) Python is a compact language with simple syntax rules (8) Python language is freely available along with its source code. (h) Working in the interactive mode is convenient for testing a single line code for instant execution. (i) In interactive mode, we cannot retype and run the statements again. 3, Multiple Choice Questions (MCQs): (a) Python is a language. (i) case-sensitive (i) case-insensitive (ii) case-independent (iv) case-based (0) is a default separator for values in the output produced by using print() command, {) Semicoton (;) i) Comma (,) (ii) \n (iv) Space (6) Python is a language because it can run seamlessly on various platforms. (i) case-sensitive (ii) cross-platform (ii) complete (iv) interpreted (a) option provides Python help and documentation. {i File (ii) edit (ii) Shell (iv) Help (e) Python comes with an integrated development environment, called 1 which can be used to create programs. {i) Shell (ii) 1OLE (ii) IDE (iv) Prompt (f) What will be the output of the following code? print (‘Hello ' + 'World!") (i) Hello World! (ii) Hello + World! (ii) HelLoworla! (iv) Hello #World! (8) To specify a different string instead of space as the Separator, .nnnmnnnmnne afgument of print() function is used. (i) are (li) end (ii) sep (iv) input {(h) print() function converts the argument or message into a 5 before displaying it on the screen. (i) string (ii) integer (ii) float (iv) keywords “ option provides various options like creating a new file, opening an existing file, etc. (i) Edit (ii) File i) Window (iv) Debug Woe mode can be used for testing small lines of code. (i) Editor (ii) Interactive (ili) Window (iv) None of these Getting Started with Python —~A SOLVED QUESTIONS 1. What is Python? Ans. Python is a high-level, interpreted, dynamically typed, object-oriented programming language that supports GUI programming, 2. Why is Python an interpreted language? ‘Ans. Python is an interpreted language because the program is processed at runtime by the interpreter and we eed not compile our program before executing it. 3. Who developed Python? ‘Ans. Python was developed by Guido van Rossum in 1991 at the National Research Institute for Mathematics, the Netherlands. 4, What does ‘IDLE’ stand for? Ans. IDLE refers to Integrated Development and Learning Environment. 5. Why is Python easy to learn? ‘Ans. Python has relatively few keywords, a simple structure and a clearly-defined syntax. This allows one to understand and work easily in a relatively short amount of time. Write any one feature of Python. ‘Ans. Python is a highly portable and cross-platform language compatible with UNIX, Windows and Macintosh, 7. Is Python a compiled or an interpreted language? (Hors) ‘Ans. The normal execution of Python program is interpreted. However, subsets of the language can be compiled. 8. Python is a free and open-source language. What do you understand by this? ‘Ans. This feature signifies that Python is freely available, /.., we can download it for free. Its source code is also easily available if we wish to modify it, which makes it an interpreted language. 9. Write some features of Python. ‘Ans. Some features of Python are as follows: (a) Itis a simple language that is easy to learn. (b) Anybody can use Python without the need to purchase a licence. (c) Python codes are machine and platform-independent. (d) Python programs support C and C++ codes, 10. In which mode of Python is the interpreter no longer active? * Ans. The interpreter is no longer active in Script mode of Python, 11. Distinguish between Python and other programming languages. ‘Ans. Python can be distinguished from other programming languages on the basis of the following: (a) Python programs run slower than other programming languages. However, Python saves time and space, as programs are 3-5 times smaller. (b) Python is a dynamically-typed language, .e., there is no need to declare variable types. This saves time ‘as compared to other programming languages. (c} Python is easier to learn as compared to other object-oriented programming languages 12, Python is a cross-platform language. Explain, Ans. Python is a cross-platform language, ie., Windows, Macintosh, Linux/Unix, etc. 13. What is the difference between Interactive mode and Script mode in Python? ‘Ans. In Interactive mode, instructions are given after the command prompt (>>>) in Python Shell. Python carries ut the given instructions and displays the result there itself. |n Script mode, Python instructions are stored in a file, generally with .py extension, and executed together in one go as a unit. Saved instructions are known as Python script or Python program, is compatible and can run well on several platforms like 14, What are the advantages and disadvantages of working in Interactive mode in Python? ‘Ans. Advantages of working in Interactive mode in Python are: (a) Itis useful for testing code. {b) In this mode, the result is obtained immediately after the execution of each line of code. Hence, it runs very fast aw Informatics Practices with Python-Xi Disadvantages of working in Interactive mode in Python are: {a) Interactive mode does not save commands in the form of a program. (b) The output appears between commands. 15, What are the advantages and disadvantages of working in Script mode in Python? ‘Ans. Advantages of working in Script mode in Python are: (a) Script mode is useful for programs that contain lengthy codes or multiple blocks of code. (b) Editing of code is easier in Script mode. Disadvantages of working in Script mode in Python are: (a) This mode is not suitable for testing code. (b) Working in this mode can be tedious when only a few lines of code need to be run. 16. What will be the output of the following? (a) print ("Hello") (b) print ( (c) print (4+6) (d) Print ( Ans. (a) Hello (b) 5.5 (c) 10 (d) Error 17. Which of the following are invalid strings in Python? (a) “Python” (b). “Python’ {c) “Python” (a) ‘Python’ (e) (Python) ‘Ans. (a), (b) and (e) are invalid strings in Python 18. What will be the output of the following? (a) >>>print (‘apple', 'mango', ‘orange’, ‘banana’, se (b) >>>print (1,2,3,4,5,end="**#*", sep="8") (6) >>>print (2,4, 6,8, 10) sprint (3, 6,9, 12,15) Ans. (a) apple@mango@orange@banana (b) 1828384 (2468 363 2 ASSERTION AND REASONING BASED QUESTION: ‘The following questions contain two statements: Assertion and Reasoning. Each question has four choices— (i), Gi), (iil), (iv) only one of which is correct. In the light of these statements, choose the most appropriate option. (i) Both A and R are true and Ris the correct explanation of A. (ii) Both A and R are true but R is not the correct explanation of A. (ii) Ais true but Ris false. (iv) Ais false but Ris true. 1, Assertion (A): Python is an object-oriented programming language. Reasoning (R): Using Python, any software can be designed. All elements in Python are treated as objects. 2. Assertion (A): Python interpreter works in Interactive mode and Script mode. Reasoning (R): Interpreter converts all code into machine language at once. 3. Assertion (A): Python uses print() method to print the value of a variable, Reasoning (R): print|) method displays the content on the system screen or console. 4. Assertion (A): Python is a cross-platform language. Reasoning (R): Python code can run on a variety of platforms such as Windows, Macintosh and Apple. 5. Assertion (A): Python is a dynamically-typed language. Reasoning (R): Python interpreter assigns variables a data type at runtime based on the variable’s value at that time. 6. Assertion (A): Python is the fastest language. Reasoning (R): Python is an interpreted language, Getting Started with Python —“k 7. Assertion (A): Python IDLE or Interpreter provides two modes to work with, create and run the scripts or code. Reasoning (R): Interactive mode comprises Python prompt (>>>) where you can simply start typing the command and display output. In Script mode, you can write Python program in a file and execute it to display the output. 8. Assertion (A): Python is a general-purpose language, ie., it can be used to create different programs. Reasoning (R): Python is used to build websites and software, automate tasks and conduct data analysis. Ans. 1. (i) 2. Gil) 3. (i) 4 (0) 5. (i) 6. (iv) 7. (i) 8. (i) UNSOLVED QUESTIONS = 1, When was Python introduced? 2. Which two languages have contributed to the development of Python as a programming language? 3. Is Python a case-sensitive language? What does this signify? 4, What is IDLE? 5. Differentiate between displaying and printing method in Python. 6. Briefly explain the salient features of Python. 7. What are the advantages of Python programming language? 8. In how many ways can you work in Python? 9. Write some limitations of Python. 10. Write instructions to the Interactive mode for the following: (2) To display the sum of 3, 8.0, 6*12 (b) To print the sum of 16, 5.0, 44.0 11. Write the output of the following, numl = 4 num2 = numl + 1 numl = 2 print (numl, nun2) Consider the following statements and write the Python command to display these statements in both Interactive mode and Script mode. Python is easy to learn and write It allows us to work in two modes: Interactive mode and Script mode. Interactive mode is also known as Python Shell and Script mode is also known as Python Editor. It is a platform-independent language. We find it interesting to work with Python. 12. 13. Write a code that prints your full name and birthday as separate strings. 14, What will happen when the following statements will be executed? (a) print (n=17) (b) print (8+3) (c) print (4.2, "hello", 6-2, "world", 15/2.0) Use Python IDLE to calculate. (a) 6+4*10 (b) (644) 10 16. Try the following code on the Python Shell and evaluate the output generated, >>> print (3.14159*7) t('I ama class XI' + ‘student") >>> print(‘I', ‘am') >>> print ("class XI student") >>> print ("I'm", 16, "years old") y Informatics Practices with Python-XI 15. >>> prin

You might also like