0% found this document useful (0 votes)
43 views

Python Assignment-1 - Updated - 240819 - 000845

Python notes and questions

Uploaded by

debadritam081
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)
43 views

Python Assignment-1 - Updated - 240819 - 000845

Python notes and questions

Uploaded by

debadritam081
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/ 7

IT workshop Lab (Python Programming Lab) (PCC_CS393)

Course Outcome :

IT workshop Lab (Python Programming Lab) (PCC_CS393)

CO# Course Outcome Action verb Knowledge level


After completion of this lab students will able to …
PCC-CS393.CO1 Interpret the fundamental Python syntax and semantics and Interpret Understand
be fluent in the use of Python control flow statements , data (K2)
types & string
PCC-CS393.CO2 Implement Conditionals and Loops statements for Python Implement Apply (K3)
Programs
PCC-CS393.CO3 Design the methods to manipulate Python programs by Design Create (K6)
utilizing the data structures like lists, dictionaries, tuples and
sets with the help of user define functions
PCC-CS393.CO4 Identify the commonly used operations involving file Identify Understand
systems and regular expressions. (K2)

PCC-CS393.CO5 Implement the Object-Oriented Programming concepts such Implement Apply (K3)
as encapsulation, inheritance and polymorphism as used in
Python

PCC-CS393.CO6 Design & Develop database related program using python Design & Create (K6)
Develop

_______________________________________________________________________________________
Page |1 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT
IT workshop Lab (Python Programming Lab) (PCC_CS393)

Assignment 1: On variable & Data Type [Related CO=CO1]

1. Create a variable named carname and assign the value „Volvo‟ to it.
2. Create a variable named x and assign the value 50 to it.
3. Create a variable called z, assign x + y to it, and display the result.
4. Insert the correct syntax to assign values to multiple variables in one line:
x __y___ z = "CSE", "IT", "ECE"
5. Insert the correct syntax to assign the same value to all three variables in one code line.
X__Y__Z__ “RCC”
6. Insert the correct keyword to make the variable x belong to the global scope.
____________ x
7. Print different types of variable using “type” method (Solved example)

x = "Hello World"
x = frozenset({"rcciit", "for",
print(x)
"rcciit","cse"})
print(type(x))
print(x)
print(type(x))
x =50
print(x) x = True
print(type(x))
print(x)
print(type(x))
x = 60.5
print(x) x = b"Rcciit"
print(type(x)) print(x)
print(type(x))
x = 3j
print(x)
output:
Hello World
print(type(x)) <class 'str'>
50
x = ["rcciit", "for", "rcciit"] <class 'int'>
print(x) 60.5
<class 'float'>
print(type(x))
3j
<class 'complex'>
x = ("rcciit", "for", "rcciit") ['rcciit', 'for', 'rcciit']
print(x) <class 'list'>
print(type(x)) ('rcciit', 'for', 'rcciit')
<class 'tuple'>
range(0, 10)
x = range(10) <class 'range'>
print(x) {'name': 'Suraj', 'age': 24}
print(type(x)) <class 'dict'>
{'for', 'rcciit'}
x = {"name": "Suraj", "age": 24} <class 'set'>
frozenset({'for', 'rcciit', 'cse'})
print(x) <class 'frozenset'>
print(type(x)) True
<class 'bool'>
x = {"rcciit", "for", "rcciit"} b'Rcciit'
<class 'bytes'>
print(x)
print(type(x))

_______________________________________________________________________________________
Page |2 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT
IT workshop Lab (Python Programming Lab) (PCC_CS393)

Assignment 2: On Conditional Statement [Related CO=CO2]

1. WAP in python to check whether number is positive or negative.


2. WAP in python to check smallest among two numbers.
3. WAP in python to check whether the year is leap year or not.
4. WAP in python to check whether a triangle is acute, obtuse or right angle triangle only two angles are given by the user.
5. WAP in python to find largest among three numbers using nested if.

Assignment 3: On for loop [Related CO=CO2]

1. WAP in python to calculate the average of first n natural numbers using for loop
2. WAP in python to print the multiplication table of n, where n is entered by the user using for loop.
3. WAP in python to print all the numbers from m-n thereby classify them as even or odd using for loop.
4. WAP in python to print prime numbers within a given range .
5. WAP in python to calculate the factorial of a number using for loop.
6. WAP in python to print the sum of first N fibonacci numbers
7. WAP in python to print the sum of first N tribonacci numbers
8. WAP in python to calculate the sum of series 1/1+22/2+32/3+……+n2/n.[print the series also]
9. WAP in python to calculate the sum of series 1+2+4+8+16… [print the series also]
10. WAP in python to calculate the sum of series 1/1! +2/2! 3/3!... [print the series also]
11. WAP in python to calculate the sum of series ((x-1)/x)+1/2((x-1)/x)2+1/3((x-1)/x)3…[print the series also]
12. WAP in python to calculate the sum of series 1/x+2/x2+3/x3+…[print the series also]
13. WAP in python to calculate the value of an investment using for loop.Input an initial value of investment and annual interest,
and calculate the value of investment over time.
14. WAP in python to generate calendar of a month given the start_day and the number of days in that month using for loop.
15. WAP in python to print the following patterns
a) b) c) d)
1 1 1 1
12 21 10 23
123 321 101 456
1234 4321 1010 7 8 9 10
12345 54321 10101 11 12 13 14 15
e) f) 1 g) h)
1 101 123454321 MADAMADAM
01 10101 1234 4321 MADA ADAM
010 1010101 123 321 MAD DAM
1010 101010101 12 21 MA AM
10101 1010101 1 1 M M
10101 12 21 MA AM
101 123 321 MAD DAM
1 1234 4321 MADA ADAM
123454321 MADAMADAM

Assignment 4: On while loop [Related CO=CO2]

1. WAP in python to given number is Armstrong number or not .

_______________________________________________________________________________________
Page |3 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT
IT workshop Lab (Python Programming Lab) (PCC_CS393)

2. WAP in python to read the numbers until -1 is encountered. Find the average of positive and negative numbers entered by the
user .
3. WAP in python to enter a decimal number. Calculate and display the binary equivalent of this number .
4. WAP in python to binary number to equivalent decimal number .
5. WAP in python to read a character until * is encountered . Also count the number of uppercase, lowercase and numbers entered
by the users.
6. WAP in python to calculate repetitive sum of the digits of the number until it becomes one digit
7. WAP in python to calculate GCD & LCM of two numbers .
8. WAP in python to print the reverse of a number and find the difference between original & reverse number .

Assignment 5: On List [Related CO=CO3]


1. Write a Python program to sum all the items in a list.
2. Write a Python program to get the largest number from a list.
3. Write a Python program to print the numbers of a specified list after removing even numbers from it.
4. Write a Python program to generate all permutations of a list in Python.
5. Write a Python program to find the index of an item in a specified list.
6. Write a Python program to find the second largest number in a list.

Assignment 6: On Touple [Related CO=CO3]


1. Write a Python program to compute element-wise sum of given tuples
2. Write a python program that has a nested list to store toppers details. Edit the details and reprint the details.
3. Write a Python program to find the repeated items of a tuple
4. Write a Python program to Sort by Frequency of second element in Tuple List
5. Write a Python program to Sort lists in tuple
6. Write a Python program to Order Tuples using external List
7. Write a Python program to Filter Tuples by Kth element from List
8. Write a Python program to find a touple from a nested touple with respect to key element search which is the first element of all
the nested touples .
9. Write a Python program to Sort Tuples by their Maximum element
10. Write a Python program to Remove nested records from tuple
11. Write a Python program to Sort by Frequency of second element in Tuple List
Sorting solved example :
#Python code to store student records
#Arrange each record by name
StdRec = ((115,'Kriyansh',485),(114,'Arvind', 460),(113,'Sruti ',486), (116, 'Krishant', 480),(111, 'Swati ', 490),(112,'Ishwarya',
489))
SOnName=sorted(StdRec, key=lambda a:a[1])
print('S. No.', 'RollNo','\t Name','\tAggregate')
for i in range(len(SOnName)):
print(i+1,'\t',SOnName[i][0],'\t',SOnName[i][1],'\t',SOnName[i][2])

Assignment 7 : On Dictionary [Related CO=CO3]

1. Write a Python script to print a dictionary where the keys are numbers between 1 and n (both included) and the values are square
of keys.
2. Write a Python program to sum all the items in a dictionary.
3. Write a Python program to count number of items in a dictionary value that is a list.
4. Write a Python program to remove duplicate values from dictionary.
5. Write a Python program to Convert two lists into a dictionary
6. Write a Python program to Replace words from Dictionary
7. Write a program to get the maximum and minimum value of dictionary.

_______________________________________________________________________________________
Page |4 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT
IT workshop Lab (Python Programming Lab) (PCC_CS393)

8. Python counter and dictionary intersection example (Make a string using deletion and rearrangement). Given two strings, find if
we can make first string from second by deleting some characters from second and rearranging remaining characters.
Input : s1 = ABHISHEKsinGH
: s2 = gfhfBHkooIHnfndSHEKsiAnG
Output : Possible

Input : s1 = Hello
: s2 = dnaKfhelddf
Output : Not Possible

Input : s1 = GeeksforGeeks
: s2 = rteksfoGrdsskGeggehes
Output : Possible
9.Given a list of elements, perform grouping of similar elements, as different key-value lists in a
dictionary.
Input : test_list = [4, 6, 6, 4, 2, 2, 4, 8, 5, 8]
Output : {4: [4, 4, 4], 6: [6, 6], 2: [2, 2], 8: [8, 8], 5: [5]}

Explanation : Similar items grouped together on occurrences.

Input : test_list = [7, 7, 7, 7]


Output : {7 : [7, 7, 7, 7]}
Explanation : Similar items grouped together on occurrences.

Assignment 8: On String [Related CO=CO1]

1. Write a python program to Create a string made of the middle three characters.
str1 = JhonDipPeta
Output : Dip

2. Write a python program to Create a new string as abbreviation of name taken as input
Example 1: Input : Netaji Subhas Chandra Bose
Output : N.S.C.Bose
Example 2: Input : Niren Dutta
Output: N.Dutta

3. Write a python program to Arrange string characters such that lowercase letters should come first
Input: PyNaTive
Output : yaivePNT
4. Write a python program to Count all letters, digits, and special symbols from a given
string
Input = P@#yn26at^i5ve!
Output : Total counts of chars, digits, and symbols
Chars = 8
Digits = 3
Symbol = 4

5. Write a program to create a new string s3 made of the first char of s1, then the last char of s2, Next, the second char of s1 and
second last char of s2, and so on. Any leftover chars go at the end of the result
s1 = Abc
s2 = Xyz
Expected Output: AzbycX

6. Write a python program to Find all occurrences of a substring in a given string by ignoring the case
str1 = Welcome to INDIA. INDIA is awesome

_______________________________________________________________________________________
Page |5 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT
IT workshop Lab (Python Programming Lab) (PCC_CS393)

Output:
The USA count is: 2
7. Write a python program to Write a program to count occurrences of all characters within a string
Input = Apple
Output :A: 1, p: 2,l: 1, e: 1
8. Write a python program to Reverse a given string
Input = BTECH
Output=HCETB
9. Write a python program to Split a string on hyphens
str1 = Emma-is-a-data-scientist
Output:
Emma
is
a
data
scientist
10. Write a python program to print a entered number in word pronounced
Input = 1978
Output=One thousand nine hundred seventy eight
Input = 108
Output=One hundred eight

Assignment 9 : On Function [Related CO=CO3]


1. Write a Python program to create a function in Python.
2. Write a Python program to create a function with variable length of arguments.
3. Write a Python program to Return multiple values from a function.
4. Write a Python program to create a function with a default argument.
5. Write a Python program to create a recursive function.
6. Write a Python program to assign a different name to function and call it through the new name.
Write a Python program to reverse a string.
Sample String : 1234abcd
Expected Output : dcba4321
7. Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an
argument.
8. Write a Python function that accepts a string and counts the number of upper and lower case letters.
Sample String : The quick Brown Fox;
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
9. Write a Python function to create and print a list where the values are the squares of numbers between 1 and 30 (both included).
10. Write a Python program that accepts a hyphen-separated sequence of words as input and prints the words in a hyphen-separated
sequence after sorting them alphabetically.
Sample Items : green-red-yellow-black-white
Expected Result : black-green-red-white-yellow

Assignment 10 : On Set [Related CO=CO3]


1. WAP in Python to create a set and add elements using a user-defined function. Also, access the elements.
2. WAP in Python to demonstrate the use of a set to remove duplicate elements from a list.
3. WAP in Python to create a frozenset from a given list of elements.
4. WAP in Python to create a set of prime numbers up to a specified number.
5. WAP in Python to find the union and intersection of two sets.
6. WAP in Python to check if a set is a subset or superset of another set using user-defined functions.
7. WAP in Python to join multiple sets into one set using the update() method.

_______________________________________________________________________________________
Page |6 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT
IT workshop Lab (Python Programming Lab) (PCC_CS393)

8. WAP in Python to slice elements from a frozenset by first converting it to a list.


9. WAP in Python to find unique elements across multiple sets.

_______________________________________________________________________________________
Page |7 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT

You might also like