0% found this document useful (0 votes)
5 views12 pages

Python Practical File

The document contains Python code snippets for various tasks, including determining if a number is odd or even, generating hollow square and left triangle patterns, and performing operations on lists. It also outlines learning objectives related to problem-solving and analytical skills in Python. Additionally, it includes specific questions and code examples for manipulating lists and calculating averages.

Uploaded by

avani.saini.2204
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)
5 views12 pages

Python Practical File

The document contains Python code snippets for various tasks, including determining if a number is odd or even, generating hollow square and left triangle patterns, and performing operations on lists. It also outlines learning objectives related to problem-solving and analytical skills in Python. Additionally, it includes specific questions and code examples for manipulating lists and calculating averages.

Uploaded by

avani.saini.2204
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/ 12

def is_odd_or_even(num):

if num % 2 == 0:
return "Even"
else:
return "Odd"

print(is_odd_or_even(7)) #
Output: Odd
# Hollow square pattern
size = 5

Python
for i in range(size):
for j in range(size):
# Print * completely in first and last row
# Print * only in first and last position in other rows
if i == 0 or i == size - 1 or j == 0 or j == size - 1:
print("*", end="")

Practical File
else:
print(" ", end="")
print()

# Left triangle star pattern


size = 5
for i in range(size):

Avani Saini, X-H, Roll no. 8


for j in range(i + 1):
print("*", end="")
print()

me(num):
m <= 1:
urn False
range(2,
*0.5) + 1):
m % i == 0:
urn False
rn True

ime(17)) #
t: True
def is_odd_or_even(num):
if num % 2 == 0:
return "Even"
else:
return "Odd"

print(is_odd_or_even(7)) #
Output: Odd
# Hollow square pattern

Term
size = 5
for i in range(size):
for j in range(size):
# Print * completely in first and last row
# Print * only in first and last position in other rows
if i == 0 or i == size - 1 or j == 0 or j == size - 1:
print("*", end="")
else:

-1-
print(" ", end="")
print()

# Left triangle star pattern


size = 5
for i in range(size):
for j in range(i + 1):
print("*", end="")
print()

me(num):
m <= 1:
urn False
range(2,
*0.5) + 1):
m % i == 0:
urn False
rn True

ime(17)) #
t: True
eturn "Even"

Index
e:
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd

- Term 1 -

Learning Objectives 1

#1 List 2

#2 Colour 3

#3 Vegetables 4

#4 Average 5

#5 Cube 6

#6 Slicing 7

#7 Even 8

#8 Greater than 50 9
eturn "Even"
e:

Learning
eturn "Odd"

(is_odd_or_even(7)) #

Objectives
ut: Odd

To inculcate problem
solving and analytical
skills

To strengthen the
concepts of Python
eturn "Even"
e:

#1 List
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd

Q. Create a list of any 5 numbers. Add two


more numbers to the list — one at the end
and one at the beginning

Code:
eturn "Even"
e:

#2 Colour
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd
Q. Given a list: colors = ['red', 'green', 'blue',
'yellow', 'pink', 'black']. Perform the
following:-
Remove 'blue' from the list.
Delete the color at index 3.
Remove the last color.
Print the list after each change.

Code:
eturn "Even"
e:

#3 Vegetables
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd
Q. Generate a list of your favorite
vegetables. Perform the following:
Print the first 4 vegetables using list
slicing.
Print all the vegetables at an even
index.
Print the entire list in reverse order.

Code:
eturn "Even"
e:

#4 Average
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd
Q. Take a list of 5 marks entered by the
user.
Calculate and print the average of these
marks.
If average is 75 or more, print
"Distinction"
If between 50 and 74, print "Pass"
Otherwise, print "Fail"

Code:
eturn "Even"
e:

#5 Cubes
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd
Q. Write a program that stores 6 numbers
in a list.
Use a loop to print each number and its
cube on the screen

Code:
eturn "Even"
e:

#6 Slicing
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd
Q. Take a list of 5 numbers. Using slicing,
print:
Every second number in the list
The last three numbers in reverse order

Code:
eturn "Even"
e:

#7 Even
eturn "Odd"

(is_odd_or_even(7)) #
ut: Odd

Q. Make a list of numbers from 1 to 20.


Print only the even numbers using a loop.

Code:
eturn "Even"
e:

#8 Greater
eturn "Odd"

(is_odd_or_even(7)) #

than 50
ut: Odd

Q. Create a list of 10 numbers. Store them


in a list. Print only those numbers which
are greater than 50

Code:

You might also like