0% found this document useful (0 votes)
7 views10 pages

PP 1902

This document is an assignment submission for a Python programming course, detailing various programming tasks and their corresponding source code. The tasks include creating and manipulating lists, tuples, and dictionaries, as well as implementing control structures like if conditions, for loops, and while loops. Additionally, it includes a function to check for prime numbers within a specified range.

Uploaded by

teamxtwasik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

PP 1902

This document is an assignment submission for a Python programming course, detailing various programming tasks and their corresponding source code. The tasks include creating and manipulating lists, tuples, and dictionaries, as well as implementing control structures like if conditions, for loops, and while loops. Additionally, it includes a function to check for prime numbers within a specified range.

Uploaded by

teamxtwasik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

February 19, 2025 [ Python programming ]

Submitted By: Syed Najam us Saqib Andrabi


Semester 4 th
Roll No : 36-CSE-2023
Course Code: PCC-CSE-431
Submitted to : Dr Manmeet Singh

1|Page
February 19, 2025 [ Python programming ]

Assignment NO: 02
INDEX
S.No Program Date
06 Write a program to create, append and remove list 19/02/2025
in python.
07 Write a program to demonstrate working with tuples 19/02/2025
in python.
08 Write a program to demonstrate working with 19/02/2025
dictionaries in python
09 Write a program to check whether a number is even 19/02/2025
or odd using if condition.
10 Write a program to demonstrate for loop 19/02/2025
11 Write a program to demonstrate while loop 19/02/2025

12 Write a program to display prime numbers between 19/02/2025


50 to 60
6. Write a python program to create, append and remove
lists in python.
2|Page
February 19, 2025 [ Python programming ]

Source Code :

# Creating list with fruits names.

fruits = ["Apple", "Orange", "Banana"]

print(fruits)

# Appending new fruits in collges list

fruits.append("Pineapple")

#checking if its added or not

print(fruits)

#adding a new fruits at a position

fruits.insert(1,"Mango")

print(fruits)

#remove a name from fruits

fruits.remove("Orange")

print(fruits)

#remove a name with an index value

del fruits[1]

# NOTE: index starts from 0 so 2nd value in list will be removed

print(fruits)

3|Page
February 19, 2025 [ Python programming ]

7. Write a program to demonstrate working with tuples in python


Source code:

# Creating tuples with fruit names.

fruits = ("apple", "banana", "grapes", "pineapple")

print ("the lists in fruits tuple is", fruits)

print ("we can't add or remove new elements in a tuple")

print ("length of the tuple fruits is:", len(fruits))

# Checking whether 'apple' is present in the tuple or not

if "apple" in fruits:

print ("Yes, 'apple' is in the fruits tuple")

8. Write a program to demonstrate working with dictionaries in


python

Source code:
# Creating a dictionary

fruits = {

"name": "apple",
4|Page
February 19, 2025 [ Python programming ]

"color": "red",

"id": "1"

print(fruits)

# Adding items to dictionary

fruits["taste"] = "sweet"

print(fruits)

# Changing values of a key

fruits["taste"] = "yummy"

print(fruits)

# To remove items

#Use pop ()

fruits.pop("taste")

print(fruits)

#Know the length using len()

print ("length of fruits is:", len(fruits))

#To copy the same dictionary use copy ()

myfruit= fruits.copy()

5|Page
February 19, 2025 [ Python programming ]

print(myfruit)

9. Write a program to check whether a number is even or odd


using if condition

x = int(input("Enter a number "))

#print(x)

if x%2== 0:

print("{} is Even".format(x))

else:

print("{} is Odd".format(x))

6|Page
February 19, 2025 [ Python programming ]

10. Write a program to demonstrate for loop

x = [0,1,2,3,4,5,6,7,8,9]

y = list(range(10))

for i in range(1,11):

print(i)

fruits = {"apple",'banana','Orange'}

for i in fruits:

print(i)

for i in range(1,11):

print(str(5).rjust(2),"*",str(i).rjust(2),"=",str(5*i).rjust(2))

7|Page
February 19, 2025 [ Python programming ]

11. Write a program to demonstrate while loop

Source Code

a,b = 0,1

8|Page
February 19, 2025 [ Python programming ]

while b < 10:

print (b,a)

a,b = b,a+b

12. Write a program to display prime numbers between 50 to 60

Source Code

def check_prime(x):

token = True

#x = int(input("Enter a num "))

for i in range(2,x):

9|Page
February 19, 2025 [ Python programming ]

if x%i == 0 & token:

print(' {} is not prime bcoz {} divides it '.format(x,i))

return False

if token:

print(' {} is prime'.format(x))

return True

for i in range(50,60):

check_prime(i)

10 | P a g e

You might also like