0% found this document useful (0 votes)
4 views8 pages

Python

Python is a simple programming language widely used in various fields like AI, games, and data analysis, characterized by its readability and ease of use. It includes basic concepts such as variables, data types, operators, conditional statements, and loops, along with common functions for user interaction. The document also provides examples of Python programs for basic tasks like printing, calculations, and pattern generation.

Uploaded by

mansie.raval
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)
4 views8 pages

Python

Python is a simple programming language widely used in various fields like AI, games, and data analysis, characterized by its readability and ease of use. It includes basic concepts such as variables, data types, operators, conditional statements, and loops, along with common functions for user interaction. The document also provides examples of Python programs for basic tasks like printing, calculations, and pattern generation.

Uploaded by

mansie.raval
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

PYTHON PROGRAMMING

❖ What is Python?
Python is a simple and easy programming language used to give instructions to a computer.
It is widely used in Artificial Intelligence, games, websites, and data analysis.
❖ Basic Features of Python
• Easy to read and write
• Uses simple English words
• Case-sensitive (A ≠ a)
• No need to declare data types
❖ Basic Concepts
• Variables – store values
Example: a = 10
• Data Types – int, float, string
Example: 10, 3.5, "Hello"
• Operators – + - * /

❖ Basic Python Functions (Class 6 Level)


Function Use
print() Displays Output
input() Takes input from user
type() Shows data type
len() Finds length
int() Converts to integer
float() Converts to decimal
str() Converts to string

❖ Conditional Statements
Conditional statements are used to make decisions in a program. They tell the
computer what to do when a condition is true or false.
Example: If it rains, take an umbrella.

❖ Types of Conditional Statements


1. if statement: The if statement runs a block of code only when the condition is true.
2. if–else statement: The else part runs when the if condition is false.
3. if–elif–else statement: Used when there are multiple conditions.
❖ Comparison Operators: Used to compare values
Operator Meaning

== Equal to
!= Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
❖ Logical Operators: Used to check more than one condition
Operator Meaning
and Both conditions are true
or Any one condition true
not Reverse the result
❖ Looping: Looping means repeating a task again and again until a condition is met.
Example: Brushing teeth every day – same action, repeated.
❖ Types of Loops in Python

1. for loop: used when we know how many times the loop will run.
➢ Known number of times
➢ Uses range()
➢ Simple and short
2. while loop: used when we do not know how many times the loop will run.
➢ Unknown number of times
➢ Uses condition
➢ Needs more care
1. Write a program to print “Hello World”.

2. Python program to find the length of a given sentence.


Code:

Output:
3. Program to add two given numbers.
Output:

Output:

4. Python Program to Check if a Number is Odd or Even Using “%”


5. Python Program to Check if a Number is Positive, Negative or 0

6. Print Average of Three Numbers in Python Using User Input


7. Python program to find whether a given single letter is a vowel or consonant.
Code:

Output:
[Link]-Angled Triangle Pattern in Python
Code:

9. Alphabet Right-Angled Triangle Pattern in Python


10. Python Program to convert Celsius to Fahrenheit Using User Input

11. Display Multiplication Table in Python Using while Loop

You might also like