CBSE Class 10  >  Class 10 Notes  >  Artificial Intelligence  >  Introduction To Code Combat Important Notes - Artificial Intelligence for Class 10

Introduction To Code Combat Important Notes - Artificial Intelligence for Class 10

What is Program?

  • A computer program consists of a set of instructions that a computer follows to perform a specific task.
  • Programs are designed to operate faster, safer and more efficiently than manual methods for the same task.
  • Programs are responsible for reading and writing data, managing memory, and carrying out calculations.
  • Programs are the fundamental components of the operating system, which oversees essential functions and the programs we create.
  • The operating system is a crucial program that handles basic tasks like memory and file management.
  • High-level programming languages such as C++, Java, Python and Ruby are used to construct programs. These languages are human-readable and writable.

Why 

Python

 for AI?

At the core of many modern artificial intelligence systems is Python. It is the language commonly used by data scientists and engineers to build AI systems and the supporting infrastructure. Several other languages - such as Lisp, Prolog, C++, and Java - can be used to create AI applications, but Python is the most popular for the following reasons.

  • Simplicity: Python’s clear syntax makes code easier to read, write and maintain. This reduces the time required to prototype and test AI models.
  • Extensive libraries: Python offers many libraries and frameworks such as NumPy, pandas, scikit-learn, TensorFlow and PyTorch that simplify data processing, modelling and evaluation.
  • Testing and debugging: Python supports interactive testing and quick debugging, which helps when developing and experimenting with AI algorithms.
  • Cross-platform compatibility: Python runs on Windows, macOS and Linux, giving a consistent environment across development and deployment platforms.
  • Customization: Python allows integration with lower-level languages when performance optimisation is required.
  • Database connectivity: Python supports connections to major databases and provides frameworks suitable for building both small and large systems.

Applications of 

Python

Python is a high-level, general-purpose programming language used widely across domains. It can be used to write virtually any program describable in code. Common application areas include:

  • Web and Internet development
  • Desktop GUI applications
  • Software development and scripting
  • Database access and data engineering
  • Business applications, automation and analytics
  • Games and 3D graphics
  • Machine learning, data science and AI applications

Installation of 

Python

  • Python is cross-platform: it runs on Windows, macOS and Linux.
  • To write and run Python programs on your computer you must install a Python interpreter.

Downloading and Setting up Python

  1. Download Python from python.org using the Downloads page: python.org/downloads
  2. Select the appropriate installer for your operating system (Windows 32-bit/64-bit, macOS, Linux/other).
  3. Run the executable installer.
  4. Follow the installer instructions and complete the installation. On Windows, it is useful to check “Add Python to PATH”.

Python IDLE installation

After installing Python you will normally use an development environment to write programs. IDLE (Integrated Development and Learning Environment) is the basic editor and shell that comes bundled with the standard Python distribution.

IDLE has two main modes:

  • Interactive mode: The IDLE shell provides a prompt where you can type single-line Python commands and get immediate results. This is useful for quick tests and learning.
  • Script mode: Script mode allows you to write multiple lines of code in a file (a source file), save it and run it later using the interpreter. Use script mode when writing programs of more than a few lines so you can edit and reuse the code.

Python Statements and Comments

Python Statement

A statement is a piece of code that can be executed by the Python interpreter. Anything that performs an action in Python is a statement. Examples include assignment statements, conditional statements, loop statements and function calls. The end of a statement is usually indicated by a newline.

Multiline statements

If a statement is too long for one physical line, you can extend it to multiple lines using the line continuation character \\ or by using grouping constructs such as parentheses (...), brackets [...] or braces {...}. This is useful for long calculations or long data structures so the code remains readable.

Python Statement

Python Comments

Comments are lines of text in source code that are ignored by the interpreter. They explain code, improve readability and help others (or your future self) understand why code was written in a certain way. There are two common styles of comments in Python.

  • Single-line comment: begins with the hash symbol #and continues to the end of the line.

    # Single line comment

  • Multiline comments:There are a few ways to write multiline comments:
    • Use several lines starting each with #:

      # Multiple line comment 1 # Multiple line comment 2

    • Use a multiline string literal (triple quotes). Although triple-quoted strings are string literals, they are often used as block comments or for documentation strings:

      """This is a multiline comment or documentation string. It can span several lines."""

Python Keywords and Identifiers

Keywords are reserved words in Python used by the interpreter to recognise the program’s structure. Keywords have fixed meanings and cannot be used as variable names, function names or identifiers. Most keywords are lowercase; booleans are True and False.

Examples of keywords include: False, class, finally, is, return, None, continue, for, lambda, try, True, def, from, nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import, pass, break, except, in, raise.

Identifiers are names given to variables, functions, classes, modules, or other objects. Rules for identifiers:

  • Identifiers can be a combination of letters (a–z, A–Z), digits (0–9) and underscore _.
  • An identifier must start with a letter or underscore; it cannot start with a digit.
  • Keywords cannot be used as identifiers.
  • Special characters such as !, @, #, $, %, ^, & etc. should not be used in identifiers.
  • Identifiers can be of any length.
  • Python is case-sensitive: Var and var are different identifiers.

Examples of valid identifiers:

  • var1
  • _var1
  • _1_var
  • var_1

Variables, Constants and Data Types

Variables

A variable is a named memory location used to store a value. In Python, a variable is created when a value is first assigned to it. Declaration is implicit; you do not need a separate declaration statement.

Rules for variable names follow the identifier rules: start with a letter or underscore, no special characters, case-sensitive.

Constants

Constants are variables whose values should not be changed during program execution. Python has no built-in constant type, but by convention constants are written in uppercase. Example:

NAME = "Rajesh Kumar" AGE = 20

Datatype

Every value in Python has a data type. Data types describe what kind of value an object holds. Important categories include Numbers, Sequences, Sets, and Mappings.

a. Number datatype

Number data types store numeric values. Four common numeric categories in Python:

  • Int:used for whole numbers. Example:

    x = 500

  • Float:used for decimal numbers. Example:

    x = 50.5

  • Complex: used for complex (imaginary) numbers; imaginary part uses j. Example:

    x = 10 + 4j

  • Boolean: holds True or False. Example:

    x = 15 > 6 type(x)

b. Sequence datatype

A sequence is an ordered, indexed collection. Python provides both mutable and immutable sequence types.

  • String:a sequence of characters. Single quotes ('') or double quotes ("") delimit strings. Example:

    name = "Rakesh kumar"

  • List:an ordered, mutable collection enclosed in square brackets. Example:

    dob = [19, "January", 1995]

  • Tuple:an ordered, immutable collection enclosed in parentheses. Example:

    newtuple = (15, 20, 20, 40, 60, 70)

c. Sets datatype

A set is an unordered collection without duplicate elements. Sets have no index and are declared using curly brackets. Example:

newset = {10, 20, 30}

d. Mapping (Dictionaries)

Dictionaries are unordered collections of key–value pairs. Keys are used to access values. Dictionaries are declared with curly brackets and a colon separates keys and values:

d = {1: 'Ajay', 'key': 2}

Operators

Operators perform operations on operands (values or variables). The same operator can behave differently for different data types. Categories of operators include:

  • Arithmetic operators
  • Assignment operators
  • Comparison (relational) operators
  • Logical operators
  • Identity operators
  • Membership operators
  • Bitwise operators

Arithmetic Operators

Used for mathematical operations such as addition, subtraction, multiplication and division. Examples include +, -, *, /, //, %, .

Arithmetic Operators

Assignment Operators

Used when assigning values to variables. The basic operator is =, and there are compound assignment operators such as +=, -=, *=, etc.

Assignment Operators

Comparison Operators

Comparison operators (also called relational operators) compare values and return True or False. Examples: ==, !=, >, <, >=, <=.

Comparison Operators

Logical Operators

Logical operators combine multiple boolean expressions. Common logical operators are and, or, not.

Logical Operators

Type Conversion

Type conversion is the process of converting a value from one data type to another. There are two kinds:

  • Implicit type conversion: Python automatically converts one data type to another when required (no user action needed).
  • Explicit type conversion: The user converts types explicitly using functions like int(), float(), str() (also called casting).

Implicit Type Conversion - Example

When combining an integer and a float, Python promotes the integer to float automatically:

x = 5 y = 2.5 z = x / y # z will be a float after execution

Explicit Type Conversion - Example

You can convert a value’s type intentionally using conversion functions:

Birth_day = 21 Birth_day = str(Birth_day)

Python Input and Output

Output Using print()

Use print() to display output on the screen (standard output). Example:

a = "Hello World!" print(a)

Output: Hello World!

User Input

Use input() to receive input from the user. The function returns a string; convert as needed. Example:

name = input("Enter your name: ") age = int(input("Enter your age: "))

The document Introduction To Code Combat Important Notes - Artificial Intelligence for Class 10 is a part of the Class 10 Course Artificial Intelligence for Class 10.
All you need of Class 10 at this link: Class 10
24 videos|67 docs|8 tests

FAQs on Introduction To Code Combat Important Notes - Artificial Intelligence for Class 10

1. Why is Python considered a popular choice for AI development?
Ans.Python is considered a popular choice for AI development due to its simplicity and readability, which allows developers to focus on solving complex problems rather than dealing with intricate syntax. Additionally, Python has a rich ecosystem of libraries and frameworks, such as TensorFlow, Keras, and PyTorch, which facilitate machine learning and deep learning tasks. Its community support and extensive documentation also make it easier for newcomers to get started with AI.
2. How can I install Python on my computer?
Ans.To install Python on your computer, you can visit the official Python website at python.org. From there, you can download the installer for your operating system (Windows, macOS, or Linux). After downloading, run the installer and follow the prompts to complete the installation. Make sure to check the box that adds Python to your system PATH to access it from the command line easily.
3. What are Python keywords and why are they important?
Ans.Python keywords are reserved words that have special meanings in the Python programming language. They cannot be used as identifiers (names for variables, functions, etc.). Examples include `if`, `else`, `for`, `while`, `def`, and `class`. Understanding keywords is important because they dictate the structure of the code and control the flow of execution, helping programmers write syntactically correct and functional code.
4. What are the basic data types available in Python?
Ans.Python has several built-in data types, including: 1. Integers (`int`): Whole numbers without a fractional component. 2. Floating-point numbers (`float`): Numbers that contain a decimal point. 3. Strings (`str`): Sequences of characters enclosed in quotes. 4. Booleans (`bool`): Represents `True` or `False` values. These data types allow you to store and manipulate different types of data in your programs.
5. How do I take user input in Python?
Ans.To take user input in Python, you can use the built-in `input()` function. This function prompts the user for input and returns it as a string. For example, you can use `name = input("Enter your name: ")` to ask the user for their name. If you need the input in a different data type, you may need to convert it using functions like `int()` or `float()` as needed.
Related Searches
pdf , MCQs, ppt, video lectures, Introduction To Code Combat Important Notes - Artificial Intelligence for Class 10, Extra Questions, Introduction To Code Combat Important Notes - Artificial Intelligence for Class 10, Exam, past year papers, mock tests for examination, Important questions, Free, study material, Semester Notes, Sample Paper, Summary, Previous Year Questions with Solutions, practice quizzes, Viva Questions, shortcuts and tricks, Introduction To Code Combat Important Notes - Artificial Intelligence for Class 10, Objective type Questions;