CodeKaroYaaro PPT python part-(5)


CodeKaroYaaro13

Uploaded on Dec 9, 2020

Category Education

We at CodeKaroYaaro empowering every kid to become a Computer Science Expert by teaching them to develop mobile apps, gaming apps, websites, web applications and AI-Powered Mobile Apps. Gone are the days when programming languages and learning how to code was like a top-secret for kids, parents were like not to give them electronic gadgets for exploring the uses of it. And mobile phones, tablets, computers, and laptops all were kept away from kids' surroundings. By the time the technology revolution took place everything had changed from traditional to digital platforms. Now, Websites, Mobile Apps, Web Apps, Gaming Apps are part of our daily life. We all are digitally connected with social sites like Facebook, Twitter, Instagram, LinkedIn, etc. We are utilizing technology for our purpose, we should also propose opportunities for learning how to code to kids so that they can explore more into technology via our programming and coding courses. Our objective is very clear towards kids' development by teaching them programming languages, block coding, python coding, etc., and opening a new world of opportunities with fun and creativity for them. We are always inspiring our little coders for learning to code in different coding languages like HTML, Java python for kids. And we will arrange more Coding Winter and Summer Camps and coding quizzes, competitions, online quizzes, and programs for kids from time to time.

Category Education

Comments

                     

CodeKaroYaaro PPT python part-(5)

GETTING TO KNOW YOUR TE A C PYTHONH PROGREAMMING PART-(5) R ADD YOUR NAME HERE FILES, MODULES AND PACKAGES  What is module and package in Python? In Python, module is the way to structure program. Each Python program file is a module, which imports other modules like objects and attributes. Mention five benefits of using Python? • Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc. • Python does not require explicit memory management as the interpreter itself • allocates the memory to new variables and free them automatically Provide easy readability due to use of square brackets • Easy-to-learn for beginners • Having the built-in data types saves programming time and effort from declaring variables  Explain how can you access a module written in Python from C? We can access a module written in Python from C by following method,Module = =PyImport_ImportModule(―‖);  How to open a new file in Python? Opening a file creates a file object. In this example, the variable f refers to the new file object. >>> f = open("test.dat","w") >>> print f The open function takes two arguments. The first is the name of the file, and the second is the mode. Mode "w" means that we are opening the file for writing.  Explain how the write method works on a file. >>> f.write("Now is the time") >>> f.write("to close the file") Closing the file tells the system that we are done writing and makes the file available for reading: >>> f.close()  Which method is used to read content of a file which is already created ? The read method reads data from the file. With no arguments, it reads the entire contents of the file: >>> text = f.read() >>> print text Now is the timeto close the file  What is a text file? Give an example for a text file. A text file is a file that contains printable characters and whitespace, organized into lines separated by newline characters. To demonstrate, we‘ll create a text file with three lines of text separated by newlines: >>> f = open("test.dat","w") >>> f.write("line one\nline two\nline three\n") >>> f.close()  What is difference between break and continue statement ? The break statement is new. Executing it breaks out of the loop; the flow of execution moves to the first statement after the loop. The continue statement ends the current iteration of the loop, but continues looping. The flow of execution moves to the top of the loop, checks the coWndhitaiotn i, sa nmd eparoncte ebdys dacirceocrdtionrgyly?. How and where is it useful? When we want to open a file somewhere else, you have to specify the path to the file, which is the name of the directory (or folder) where the file is located: >>> f = open("/usr/share/dict/words","r") >> > printf.readline() Aarhus This example opens a file named words that resides in a directory named dict, which resides in share, which resides in usr, which resides in the top- level directory of the system, called .  Explain pickling and how import pickle works. Pickling is so called because it ―preserves‖ data structures. The pickle module contains the necessary commands. To use it, import pickle and then open the file in the usual way: >>> import pickle >>> f = open("test.pck","w")  What is the difference between break and continue statement? The break statement is new. Executing it breaks out of the loop; the flow of execution moves to the first statement after the loop. The continue statement ends the current iteration of the loop, but continues looping. The flow of execution moves to the top of the loop, checks the condition, and proceeds accordingly.  Explain pickling and how import pickle works. Pickling is so called because it ―preserves‖ data structures. The pickle module contains the necessary commands. To use it, import pickle and then open the file in the usual way: >>> import pickle >>> f = open("test.pck","w")  What is module and package in Python? In Python, module is the way to structure program. Each Python program file is a module, which imports other modules like objects and attributes.  Explain how can you access a module written in Python from C? We can access a module written in Python from C by following method,Module = =PyImport_ImportModule(―‖);  Mention five benefits of using Python? • Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc. • Python does not require explicit memory management as the interpreter itself • allocates the memory to new variables and free them automatically Provide easy readability due to use of square brackets • Easy-to-learn for beginners • Having the built-in data types saves programming time and effort from declaring variables  How to open a new file in Python? Opening a file creates a file object. In this example, the variable f refers to the new file object. >>> f = open("test.dat","w") >>> print f The open function takes two arguments. The first is the name of the file, and the second is the mode. Mode "w" means that we are opening the file for wriEtinxgp. lain how the write method works on a file. >>> f.write("Now is the time") >>> f.write("to close the file") Closing the file tells the system that we are done writing and makes the file available for reading: >>> f.close()  What is a text file? Give an example for a text file. A text file is a file that contains printable characters and whitespace, organized into lines separated by newline characters. To demonstrate, we‘ll create a text file with three lines of text separated by newlines: >>> f = open("test.dat","w") >>> f.write("line one\nline two\nline three\n") >>> f.close()  What is an exception? Explain with few examples. Whenever a runtime error occurs, it creates an exception. Usually, the program stops and Python prints an error message. For example, dividing by zero creates an exception: >>> print 55/0 ZeroDivisionError: integer division or modulo So does accessing a nonexistent list item: >>> a = [] >>> print a[5] IndexError: list index out of range Or accessing a key that isn‘t in the dictionary: >>> b = {} >>> print b[‘what‘] KeyError: what  List some few common Exception types and explain when they occur. • ArithmeticError- Base class for all errors that occur for numeric calculations. • OverflowError- Raised when a calculation exceeds maximum limit for a numeric type. • ZeroDivisionError- Raised when division or modulo by zero takes o place. • ImportError- Raised when an import statement fails. • IndexError- Raised when an index is not found in a sequence. • RuntimeError- Raised when a generated error does not fall into any category.  Write a simple program which illustrates Handling Exceptions. x=int(input(―Please enter a number:‖)) break except ValueError: print(―Oops! That was no valid number. Try again…‖)  What are packages in Python? A package is a collection of Python modules. Packages allow us to structure a collection of modules. Having a directory of modules allows us to have modules contained within other modules. This allows us to use qualified module names, clarifying the organization of our software.  Explain what is meant by namespaces and scoping. Variables are names or identifiers that map to objects. A namespace is a dictionary of variable names/keys and their corresponding object values. A python statement can access variables in a local namespace and global namespace. If the local and global variables have the same name, the local variable shadows the global variable. Each function has its own local namespace. We are going to have a great year learning toSgetLher!For moIreD infoErma tioTn pIleaTse cEontact us at : https://www.codekaroyaaro.com/ [email protected] 7972289701 https://www.facebook.com/codekaroyaaro https://www.instagram.com/codekaroyaaro/? igshid=1nb6afsffwzd https://www.linkedin.com/company/codekaroya aro https://www.youtube.com/channel/UC0GUyPIpdDVJQMu gEtkH8Pw