0% found this document useful (0 votes)
3 views7 pages

7th Python

The document provides an overview of Python programming concepts, including IDLE, print functions, loops, and lists. It includes definitions, examples, and practice questions related to Python syntax and operations. Key topics covered are script mode, arithmetic and relational operators, loop structures, and list manipulation techniques.

Uploaded by

aarvimukesh
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)
3 views7 pages

7th Python

The document provides an overview of Python programming concepts, including IDLE, print functions, loops, and lists. It includes definitions, examples, and practice questions related to Python syntax and operations. Key topics covered are script mode, arithmetic and relational operators, loop structures, and list manipulation techniques.

Uploaded by

aarvimukesh
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 IDLE Map

Term Explanation
IDLE Integrated Development & Learning Environment
Print Function Used to display output
Script Mode Writing and saving a program as .py file
Run Module To execute the script

2. Match the Following:

A B
Print Function Displays output
input() Accepts user data
% Modulus operator
== Checks equality
if statement Checks condition

3. Fill in the Blanks:

1. Python files have the extension .py.


2. print() is used to display output on the screen.
3. input() function is used to take values from the user.
4. Relational operators are used for comparing values.

4. Arithmetic Operators Format Table:

Operator Symbol Meaning


Addition + Adds two numbers
Subtraction - Subtracts numbers
Multiplication * Multiplies numbers
Division / Divides numbers
Modulus % Gives remainder

5. Relational Operators Map:

Operator Meaning
> Greater than
< Less than
== Equal to
>= Greater than or equal to
<= Less than or equal to
!= Not equal to
6. Logical Operators:

Operator Use
and Both conditions must be true
or Any one condition should be true
not Reverses the result

7. Script Mode Steps Format:

1. Open IDLE.
2. Click on File → New File.
3. Type the program.
4. Click on Run → Run Module.
5. Save the file with .py extension.
6. View the output in the Shell.

8. Sample IF-ELSE Structure:


if condition:
# statements
else:
# statements

9. Practice Questions:

✔ Fill in the blanks:


Python’s output display is shown using print() function.

✔ Write the output:

print(5+2)

Output: 7

✔ Write a program to check if a number is positive or not.

✔ What is the difference between = and == in Python?


= is for assignment, == checks equality.
Concept Map – Loops in Python

Type of
When to Use Example (Real Life)
Loop
Print numbers 1 to 10, 5 rounds of
FOR Loop Number of repetitions is known
jogging
Number of repetitions is
WHILE Loop Toss coin till Heads, fill bucket till full
unknown

2. Fill in the Blanks

1. A FOR loop is used when the number of repetitions is known.


2. A WHILE loop runs as long as the given condition is True.
3. The break statement is used to exit a loop.
4. The continue statement is used to skip the current iteration of the loop.

3. FOR Loop Format


for i in range(start, stop, step):
# statements

✔ Example:

for i in range(1, 6):


print(i)

Output:
12345

4. WHILE Loop Format


<initial value>
while <condition>:
# statements
<update value>

✔ Example:

count = 1
while count <= 5:
print(count)
count += 1

Output:
12345

5. Match the Following


A B
FOR Loop Known repetitions
WHILE Loop Unknown repetitions
break Exits the loop
continue Skips to next loop iteration

6. Jump Statements Map

Statement Purpose
break Exit loop completely
continue Skip the rest of the code in the loop body and start next iteration

7. Sample Question & Answer (4 Q&A)

✔ Q1: What is the purpose of the range() function in a FOR loop?


A: To generate a sequence of numbers for the loop to run through.

✔ Q2: What will happen if the condition in a while loop is always True?
A: The loop will run forever (infinite loop).

✔ Q3: What is the difference between break and continue?


A: break stops the loop; continue skips the rest of the code in the current loop cycle.

✔ Q4: Write a FOR loop to print the first 5 even numbers.


A:

for i in range(2, 11, 2):


print(i)

Output: 2 4 6 8 10

8. Practice Questions (For Students)

1. Write a program using while loop to print numbers 1 to 5.


2. What happens when you remove the update statement in a while loop?
3. Predict the output:

for i in 'abc':
print(i*3)

4. Write a FOR loop to print your name 3 times.

Python Lists - Summary Notes (2.3)


What is a Python List?

• A list is a collection of items stored in sequential memory.


• Items are enclosed in square brackets [ ] and separated by commas.
• Example: grocery = ["Milk", "Bread", "Eggs"]

2.3.1 Creating Lists

Method Example

list() with range() list(range(5)) ➔ [0,1,2,3,4]

Square Brackets items = [1, 2, 3]

User input with for loop for i in range(n): ...

Using eval() L = eval(input())

Note: Use [element] when adding to list in loop. Direct int values like + 7 will cause error.

2.3.2 Accessing List Elements

• Index starts from 0.


• L[0] returns first element.
• Accessing out of bounds: IndexError.

Accessing using:

• Direct value: for i in list:


• Index: for i in range(len(list)): then list[i]

Fill in the blanks:

1st element of L = L[__]


Last element of L = L[__]

2.3.3 Updating Lists

✏️ 1. Changing Elements
L[2] = "new value"
➕ 2. Adding Elements

• list + [new]
• append(value) ➔ adds at end
• insert(index, value) ➔ inserts at position
➖ 3. Deleting Elements
Method Description Example

pop(index) Removes and returns element [Link](2)

pop() Removes last element [Link]()

remove(value) Removes first occurrence of value [Link]("item")

Note: Removing by value not present gives error.

🔄 4. Sorting and Reversing


[Link]() # ascending
[Link]() # reverse current order
[Link](reverse=True) # descending

2.3.4 Operators on Lists

Operator Purpose Example

+ Concatenation [1,2]+[3,4] ➔ [1,2,3,4]

* Replication [0]*3 ➔ [0,0,0]

2.3.5 Practice Time!

Match the Following:

Statement Function

Remove 2nd item pop(1)

Add at end append()

Add at beginning insert(0, val)

Remove by value remove(val)

Predict Output:

L1 = [1,2,3]; L2 = [4,5,6];
L3 = L2 + L1
print(L3)

Output: [4,5,6,1,2,3]

Fill in the code:

# Sum of even numbers


L = eval(input("Enter list: "))
sum_even = 0
for i in L:
if type(i)==int and i%2==0:
sum_even += i
print(sum_even)
2.3.6 Predict Output

Code:

L1 = [1,2,3]; L2 = [4,5,6]
print(L2 + L1)

Expected Output: [4, 5, 6, 1, 2, 3]

❌ 2.3.7 Fix the Errors

Incorrect Code:

L = [1, 2, 3]
[Link] 4
print L

You might also like