Python Assignment-1 - Updated - 240819 - 000845
Python Assignment-1 - Updated - 240819 - 000845
Course Outcome :
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)
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)
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
_______________________________________________________________________________________
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 .
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]}
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
_______________________________________________________________________________________
Page |6 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT
IT workshop Lab (Python Programming Lab) (PCC_CS393)
_______________________________________________________________________________________
Page |7 © Rajib Saha , Assistant Professor, Dept. of CSE, RCCIIT