










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
For high school projects. Here is a project on python with output.You can take it for a reference.
Typology: Exercises
1 / 50
This page cannot be seen from the preview
Don't miss anything!











































On special offer
____________________Some Exceptions______________________ EXCEPTION NAME DESCRIPTION OverflowError() Raised when a calculation exceeds maximum limit for a numeric type. 0ZeroDivisonError() Raised when division or modulo by zero takes place for all numeric types. EOFError() Raised when there is no input from either the raw_input() or input() function and the end of file is reached. ImportError() Raised when an import statement fails. IndexError() Raised when an index is not found in a sequence. NameError() Raised when an identifier is not found in the local or global namespace. IOError() Raised when an input/ output operation fails, such as the print statement or the open() function when trying to open a file that does not exist. TypeError() Raised when an operation or function is attempted that is invalid for the specified data type. ValueError() Raised when the built-in function for a data type has the valid type of arguments, but the arguments have invalid values specified. ______________________Generators______________________ A generator is simply a function which returns an object on which you can call next, such that for every call it returns some value, until it raises a StopIteration exception, signaling that all values have been generated. Such an object is called an iterator. Normal functions return a single value using return, just like in Java. In Python, however, there is an alternative, called yield. Using yield anywhere in a function makes it a generator
>>> def myGen(n): ... yield n ... yield n + 1 ... >>> g = myGen(6) >>> next(g) 6 >>> next(g) 7
__________________Opening and Closing____________________ The first thing to do when you are working with files in Python isto open thefile. When you open the files, you can specify with parameters how you want to open them. The "r" is for reading, the "w" for writing and the "a" for appending. This opens the filename for reading. By default, the file is opened with the "r" parameter. fh = open("filename_here", "r") This opens the fhe file for writing. It will create the file if it doesn't exist, and if it does, it will overwrite it. fh =open("filename_here", "w") This opens the fhe file in appending mode. That means, it will be open for writing and everything will be written to the end of the file.
file.The readlines function reads all rows and retains the newlines character that is at the end of every row. eg. fh = open("filename", "r") content = fh.readlines() print content.rstrip() print content[:-1]
The functions for writing are write and writelines ---Write--- To write a fixed sequence of characters to a file eg. fh = open("hello.txt","w") write("Hello World") ----Writeline---- With the writeline function you can write a list of strings to a file eg. fh = open("hello.txt", "w") lines_of_text = ["a line of text", "another line of text", "a third line"] fh.writelines(lines_of_text)
_________________Function defined in module___________________ A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand and use. A module is a Python object with arbitrarily named attributes that you can bind and reference. Simply, a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code. Example: The Python code for a module named aname normally resides in a file named aname.py. Here's an example of a simple module, support.py def print_func( par ): print "Hello : ", par return The import Statement You can use any Python source file as a module by executing an import statement in some other Python source file. The import has the following syntax: import module1[, module2[,... moduleN] When the interpreter encounters an import statement, it imports the module if the module is present in the search path. A search path is a list of directories that the interpreter searches before importing a module. For example, to import the module hello.py, you need to put the following command at the top of the script -
>>>import support
Return a copy of s, but with upper case letters converted to lower case. 6.string.find(s, sub[, start[, end]]): Return the lowest index in s where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices. 7.string.islower(): This method checks if the string is in lowercase and returns true if all the characters are in lowercase. 8.string.isupper(): This method checks if all the characters in the string are in uppercase. If any character is in lower case, it would return false otherwise true.
Python offers 5 different types of data structure.
Queues data structure are FIFO(First In First Out ) lists , where take place at "rear" end of queue deletions take place at the "front" end of the queue.
This project has been created to fulfill the requirement of the CBSE Senior Secondary Examination Class XII for Computer science. This project is been created by Ashwani singh of class XII under the guidance of Mr. Jaideep sir .This project is created to teach a new beginner how to code with python. WORKING DESCRIPTION