0% found this document useful (0 votes)
31 views1 page

Python Programming Exercises PDF

The document outlines 20 tasks related to Python programming concepts and techniques: 1) Implementing forward chaining for problem solving using a Python program. 2) Solving the 8 queens problem using assumptions in a Python program. 3) Demonstrating best first search on an AI problem using a Python program. 4) Defining an Employee class with methods to set/display attributes like ID, name, age, and salary. 5) Illustrating modifiers with Python code.

Uploaded by

KAVYASHREE B L
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Python Programming Exercises PDF

The document outlines 20 tasks related to Python programming concepts and techniques: 1) Implementing forward chaining for problem solving using a Python program. 2) Solving the 8 queens problem using assumptions in a Python program. 3) Demonstrating best first search on an AI problem using a Python program. 4) Defining an Employee class with methods to set/display attributes like ID, name, age, and salary. 5) Illustrating modifiers with Python code.

Uploaded by

KAVYASHREE B L
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Write a python program to implement problem solving strategies using forward chaining
technique. (refer lab program)
2. Write a python program to Solve 8-queens problem using suitable assumptions.(refer lab
program)
3. Write a python program to demonstrate Best first search algorithm on any AI problem?
(refer lab program)
4. Define classes and objects in Python. Create a class called Employee and initialize it
with employee id and name. Design methods to:
(i) i) setAge_to assign age to employee.
(ii) ii) setSalary_to assign salary to the employee.
iii) Display_to display all information of the employee.
5. Illustrate the concept of modifier with Python code.
6. Explain init and __str__ method with an example Python Program.
7. Define polymorphism? Demonstrate polymorphism with function to find histogram to
count the number of times each letter appears in a word and in a sentence.
8. Illustrate the concept of pure function with Python code.
9. Define Class Diagram. Discuss the need for representing class relationships using Class
Diagram with suitable example.
10. What is class? How do we define a class in python? How to instantiate the class and
how class members are accessed?
11. Write a python program that uses datetime module within a class , takes a birthday as
input and prints user’s age and the number of days, hours ,minutes and seconds until
their next birthday.
12. Explain operator overloading with example.
13. Illustrate the concept of inheritance with example
14. What is JSON? Briefly explain the json module of Python. Demonstrate with a Python
program.
15. Discuss the Creation, Encryption and Decryption of a PDF.
16. Write a python program to give search keyword from command line arguments and open
the browser tab for each result page.
17. Use the datetime module to write a program that gets the current date and prints the day
of the week.
18. Write a python program to access a cell in a worksheet.
19. Define and illustrate the CSV file. What are the advantages of CSV file?
20. Write a program to get a list of all files with the .pdf extension in the current working
directory and sort them.

Common questions

Powered by AI

JSON (JavaScript Object Notation) is a lightweight data interchange format easy for humans to read and write, and machines to parse and generate. Python's `json` module can parse JSON strings into Python dictionaries and lists and convert Python objects into JSON strings. The module provides `json.load` to parse JSON from files and `json.dump` for writing Python data structures to JSON files, enabling seamless data exchange between disparate systems .

A Class Diagram is a type of static structure diagram in UML that describes the structure of a system by showing its classes, attributes, operations, and the relationships among objects. It is crucial for visually representing class relationships, making it easier to understand the architecture and dependencies of a system. By illustrating associations, dependencies, and other interactions, Class Diagrams facilitate communication among developers and stakeholders, ensuring alignment on system design .

Forward chaining is a method used in artificial intelligence to infer conclusions from a set of known facts and rules. It involves starting with the available data and using inference rules to extract more data until a goal is reached. In Python, this can be implemented by creating a function that continuously applies a set of logic rules to known facts, checking a condition after each rule is applied to see if a specified goal is achieved. Each rule typically consists of an antecedent and a consequent, and forward chaining processes all rules whose antecedents are satisfied by the known facts .

The `__init__` method initializes an instance of a class in Python, setting initial values for instance variables. The `__str__` method returns a human-readable string representation of an object, useful for debugging and logging. An example includes a class `Person` where `__init__` sets name and age fields, and `__str__` returns 'Person(name: {}, age: {})'. Implementing these methods makes the class more intuitive and easier to use .

Operator overloading in Python allows operators to be redefined and used with user-defined data types. It is implemented using special methods, such as `__add__` for the '+' operator. For example, overloading '+' in a class `Vector` to add vector objects involves defining `__add__` so that it takes another `Vector` object and returns a new `Vector` whose components are the element-wise sum of the two input vectors. This makes operations on complex data types intuitive .

The `datetime` module provides classes for manipulating dates and times in Python. A program can take a user's birthday as input and compute the time until their next birthday by comparing the current date to the next occurrence of the birthdate. Using `datetime` objects, subtraction yields a `timedelta` object, which can be decomposed into days, hours, minutes, etc., to provide a detailed countdown to the birthdate .

The Best First Search algorithm is a pathfinding algorithm in artificial intelligence that uses a priority queue to explore paths by selecting the path that appears to be the best according to a specified heuristic. It evaluates the paths based on a search heuristic, prioritizing those paths which seem closest to the goal. A Python demonstration involves defining a priority queue to keep track of frontiers, implementing a node evaluation function using the heuristic, and developing a loop that explores paths until the goal is found or all paths are exhausted .

Inheritance in Python allows a new class, called a subclass, to inherit attributes and methods from another class, the superclass. This promotes code reuse and establishes a subtype relationship. For example, a class `Animal` with methods `eat` and `sleep` could be subclassed by `Dog`, which inherits these methods but also defines its own method, `bark`. The new class can override existing methods or extend them with additional functionality .

CSV files offer advantages such as human readability, ease of use, and portability across different software, making them ideal for data storage and transfer. They can be illustrated in Python using the built-in `csv` module to read and write data. The module allows for efficient parsing of CSV files, enabling operations like filtering and sorting data, which make CSV a preferred choice for data management tasks in Python .

Polymorphism in Python allows the same function to operate on different types of objects. This can be demonstrated by creating a histogram function that accepts either a word or a sentence as input and counts the occurrences of each letter. By defining the function to process strings character by character, the function is polymorphic, capable of handling both types of input without modification to its core logic, thus implementing polymorphism effectively .

You might also like