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

Class IX Python Programs

Uploaded by

psongs26
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)
14 views4 pages

Class IX Python Programs

Uploaded by

psongs26
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
You are on page 1/ 4

Class IX

AI 417

Introduction to AI:
Python is a high-level, interpreted, general-purpose programming language that is widely used
for web development, data analysis, artificial intelligence, automation, software development,
and more. It was created by Guido van Rossum and first released in 1991.

Why is Python Popular?

●​ Simple and easy to learn: Python uses clear and concise syntax similar to the English
language.​

●​ Versatile: It can be used for small scripts or large-scale enterprise applications.​

●​ Wide range of libraries: Python has rich libraries and frameworks for various domains
like web (Django, Flask), data science (Pandas, NumPy), machine learning (Scikit-learn,
TensorFlow), and more.​

●​ Community support: Python has a large and active global community that continuously
contributes to its growth and improvement.​

Key Features of Python

●​ Interpreted Language: Python code is executed line by line, which makes debugging
easier.​

●​ Dynamically Typed: No need to declare variable types explicitly.​

●​ Platform Independent: Python code can run on different operating systems without
modification.​

●​ Object-Oriented: Supports object-oriented programming concepts like classes and


inheritance.​

●​ Free and Open Source: Python is freely available and can be modified as per the user's
needs.

What are Variables in Python?

A variable is a name used to store data values in a program. Think of a variable as a


container or a label that holds some information which can change or vary during the program.
Example:

name = "Alice"

age = 14

marks = 89.5

Here:

●​ name is a variable holding the value "Alice"​

●​ age holds 14​

●​ marks holds 89.5

Rules for Writing Variables in Python

Here are the basic rules you must follow when naming variables:

✅ Valid Rules:
1.​Variable names can contain letters, digits, and underscores​
E.g., student1, total_marks, age_12​

2.​Variable names must begin with a letter or underscore (_)​


E.g., _score, a1, name​

3.​Variable names are case-sensitive​


E.g., name and Name are different​

4.​You cannot use Python keywords as variable names​


E.g., if, while, class, print — ❌ invalid as variable names
Some Python programs:

1. Program to Add Two Numbers

a = 10
b = 5
sum = a + b
print("Sum:", sum)

Output:

Sum: 15

2. Program to Find the Square of a Number


num = 6
square = num * num
print("Square:", square)

Output:

Square: 36

3. Program to Take User Input and Display It

name = input("Enter your name: ")


print("Hello", name)

Output:

Enter your name: Sam


Hello Sam

4. Program to Find the Largest of Two Numbers

a = 8
b = 12
if a > b:
print("Largest number is", a)
else:
print("Largest number is", b)

Output:
Largest number is 12

5. Program to Find the Largest of Two Numbers

a = 8
b = 12
if a > b:
print("Largest number is", a)
else:
print("Largest number is", b)

Output:

Largest number is 12

You might also like