0% found this document useful (0 votes)
10 views4 pages

Assignment Ai

The document outlines key concepts in computer science, including the differences between declarative and imperative knowledge, fixed and stored program computers, and algorithms. It also discusses general-purpose versus targeted programming languages, advantages of Python, object introspection, the functionality of the '?' operator, and the use of the %run command in Jupyter Notebook. Additionally, it provides a comparison between scripts and libraries in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Assignment Ai

The document outlines key concepts in computer science, including the differences between declarative and imperative knowledge, fixed and stored program computers, and algorithms. It also discusses general-purpose versus targeted programming languages, advantages of Python, object introspection, the functionality of the '?' operator, and the use of the %run command in Jupyter Notebook. Additionally, it provides a comparison between scripts and libraries in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT- 1

Q1. Difference between Declarative and Imperative Knowledge


Feature Declarative Knowledge Imperative Knowledge
Definition Describes what something is Describes how to do something
Focus Facts, truths, and relationships Procedures, steps, and instructions
"To go to Paris, take a flight, book a
Example "Paris is the capital of France."
hotel, and visit landmarks."
Use in Functional and logic Procedural and object-oriented
Programming programming (e.g., SQL, Prolog) programming (e.g., Python, C)
More abstract, used for
Flexibility More detailed, focuses on execution
reasoning
Learning
Understanding principles Practicing steps to solve problems
Approach
Examples in AI Knowledge representation Algorithms and programs

Q2. Fixed Computer vs. Stored Program Computer


Feature Fixed Computer Stored Program Computer
A computer where programs are A computer that stores and executes
Definition
hardwired into hardware programs from memory
More flexible, can run different
Flexibility Limited, designed for specific tasks
programs
Example Early calculators, hardware circuits Modern computers, smartphones
Modificati
Requires physical changes Can update software easily
on
Embedded systems, specific control
Usage General-purpose computing
systems
Reads, interprets, and executes
Processing Executes predefined instructions
programs from memory

Q3. Define Algorithm


An algorithm is a step-by-step procedure or set of instructions designed to perform a
specific task. It provides a systematic way to solve a problem efficiently.
Example: Algorithm to add two numbers:
1. Take two numbers as input.
2. Add the numbers.
3. Display the result.
Characteristics of an Algorithm:
● Input: Takes input values.
● Output: Produces a result.
● Definiteness: Clear and unambiguous.
● Effectiveness: Simple and executable steps.
● Finiteness: Must terminate after a finite number of steps.

Q4. What is a General Language? Give Reasons to Use Targeted Language


A general-purpose language (GPL) is a programming language designed to solve a wide
variety of problems. Examples include Python, Java, and C++.
A targeted language (domain-specific language, DSL) is specialized for a specific task, such
as SQL (databases), HTML (web design), and MATLAB (mathematical computing).
Reasons to Use a Targeted Language:
1. Efficiency: Optimized for specific tasks.
2. Simplicity: Easier to use for a particular domain.
3. Performance: Faster execution in specialized areas.
4. Maintainability: Reduces complexity in domain-specific applications.
5. Readability: Uses domain-specific syntax that is easy to understand.

Q5. Advantages of Python (Simple & Short) + Differences Table


Advantages of Python:
1. Easy to Learn: Simple syntax like English.
2. Short Code: Requires fewer lines compared to C/C++.
3. High-Level Language: No need to manage memory manually.
4. Interpreted Language: No compilation required.
5. Large Libraries: Prebuilt modules for different applications.
6. Cross-Platform: Works on Windows, Mac, and Linux.
7. Community Support: Large user base and extensive documentation.
Python vs Other Languages (7 Differences)
Feature Python C++
Syntax Simple, English-like Complex, requires more code
Compilation Interpreted Compiled
Memory Automatic (Garbage
Manual (Pointers)
Management Collection)
Speed Slower Faster
Extensive (e.g., NumPy,
Libraries Limited built-in libraries
TensorFlow)
AI, web development, Game development, system
Use Cases
scripting programming
Code Length Shorter Longer

Q6. Object Introspection & Functionality of ? Operator


Object Introspection:
It is the ability of a program to examine the type and properties of an object at runtime.
Python provides several built-in functions for introspection, such as:
● type(object) → Returns the type of an object.
● dir(object) → Lists all attributes and methods of an object.
● id(object) → Returns the memory address of an object.
Functionality of ? Operator (in Python and Jupyter Notebook):
● ?function_name → Displays documentation of a function in Jupyter Notebook.
● object? → Shows details of the object.
● ??object → Shows the full source code (if available).

Q7. What is the %run Command?


The %run command in Jupyter Notebook is used to execute a Python script (.py file) within
the notebook.
Example:
python
CopyEdit
%run myscript.py
This will execute myscript.py and display the output.
Difference Between Script and Library:
Feature Script Library
Definiti A file containing Python code meant to be A collection of reusable code
on executed modules
Provides functions and classes for
Purpose Runs a program to achieve a task
reuse
Imported using import
Usage Direct execution
module_name
Exampl
myscript.py (a Python script) numpy, pandas (Python libraries)
e

You might also like