Skip to content

Repository of all Assigments of Advanced Python Programming of CDAC PG-DAI Course

Notifications You must be signed in to change notification settings

Viru9029/Advanced_Python_Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 

Repository files navigation

Advanced_Python_Programming

Repository of all Assigments of Advanced Python Programming of CDAC PG-DAI Course

Lab Exercise – 1

Q1: Write a Python program which accept the radius of a circle from the user and compute the area. Sample Output : r = 1.1 Area = 3.8013271108436504

Q2: Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.

Q3: Write a Python Program to make a simple calculator that can add, subtract, multiply and divide

Q4: Write a Python Program to calculate the square root

Q5: Write a Python Program to Solve the quadratic equation ax**2 + bx + c = 0 Coeffients a, b and c are provided by the user [Hint: import complex math module - import cmath]

Q6: Write a Python Program to find the area of triangle Three sides of the triangle a, b and c are provided by the user

Q7: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits without using any loop. (Hint: Use the modulus operator ‘%’)

Q8: Write a Python program to print the following string in a specific format image

Q9: Write a Python program to display your details like name, age, address in three different lines.

Q10. Create a string containing both a single quote a double quote

Q11.Create a triple quoted string that contains single and double quotes.

Q12.Create a character, then obtain its integer representation.

Q13.Create a single string containing 5 copies of the string 'abc'.

Q14.Use the multiplication operator to create a "line" of 50 dashes.

Q15.Convert a string to all upper case.

Q16 : Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string.

Q17: a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself. Sample String : 'restart' Expected Result : 'resta$t'

Q18: Write a Python program to get a single string from two given strings, separated by a space and swap the first two characters of each string. Sample String : 'abc', 'xyz' Expected Result : 'xyc abz'

Lab Exercise - 3 [Based on Python Data Types (String, List, Tuple & Conditional statements]

Q19: Write a Python program to sum all the items in a list.

Q20: Write a Python program to get the largest number from a list.

Q21: Write a Python program to get the smallest number from a list.

Q22: Write a Python program to display the first and last colors from the following list. color_list = ["Red","Green","White" ,"Black"]

Q23: Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the given string is already ends with 'ing' then add 'ly' instead.

Q24: The marks obtained by a student in 5 different Subjects are input through a keyboard. The Student gets a division as per the following rules.

  1. Percentage above or equal to 60 – First Division
  2. Percentage between 50 and 59 – Second Division
  3. Percentage between 40 and 49 – Third Division
  4. Percentage less than 40 – Fail Write a python program to Display the result based on the above Criteria.

Q25: write a Python program to find the largest number among the three input numbers

Q26: Write a Python program to check if the input year is a leap year or not.

Q27: write a Program to check if a string is palindrome or not

Q28: write a Program to sort alphabetically the words form a string provided by the user. [You can use split() method to split string into a list of words. ]

Q29: Given a nested list. Write a python program to extend it with adding sub list ["h", "i", "j"] in a such a way that it will look like the following list Given List: list1 = ["a", "b", ["c", ["d", "e", ["f", "g"], "k"], "l"], "m", "n"] Sub List to be added = ["h", "i", "j"] Expected output: ['a', 'b', ['c', ['d', 'e', ['f', 'g', 'h', 'i', 'j'], 'k'], 'l'], 'm', 'n']

Q30: Write a python program for Given a Python list, to find value 20 in the list, and if it is present, replace it with 200. Only update the first occurrence of a value list1 = [5, 10, 15, 20, 25, 50, 20] Expected output: list1 = [5, 10, 15, 200, 25, 50, 20]

Lab Exercise 4 [Based on Python data types, conditional statements & Loops]

Q31: Write a python program to add all the odd numbers from 0 to 20.

Q32: Write a python program to find the sum of all integers greater than 100 and less than 200.

Q33: Write a program to display the sum of square of the first ten even natural numbers // (22+ 44 + 66 + 88 + 1010 + 1212 + 14 * 14 + 16 * 16 + 1818 + 2020)

Q34: Write a python program to display ascii characters from 65 to 90 image

Q35: Display ascii characters from 48 to 57. image

Q36: Display the following output with the help of Ascii character. image

Q37: Write a python program for given a Python list you should be able to display Python list in the following order L1 = [100, 200, 300, 400, 500] Expected output: [500, 400, 300, 200, 100]

Q38: Write a Python program to concatenate following dictionaries to create a new one. Sample Dictionary : dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60} Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

Q39: Write a Python program to add key to a dictionary. Sample Dictionary : {0: 10, 1: 20} Expected Result : {0: 10, 1: 20, 2: 30}

Q40: Write a Python program to print out a set containing all the colors from a list which are not present in another list Test Data : color_list_1 = set(["White", "Black", "Red"]) color_list_2 = set(["Red", "Green"])

Q41: Given a Python list. Write a python program to turn every item of a list into its square List1 = [1, 2, 3, 4, 5, 6, 7] Expected output: [1, 4, 9, 16, 25, 36, 49]

Q42: Program to count the number of each vowel in a string.

Q43:Write a python program to Access the value of key ‘history’ from the following dictionarysampleDict = { "class":{ "student":{ "name":"Mike", "marks":{ "physics":70, "history":80 } } } }

Q 44: write a Program to Remove Punctuations from a String provided by the user. [Hint: use punctuation attribute of string module to get all punctuations (i.e. !"#$%&'()*+,- ./:;<=>?@[\]^_`{|}~ ) ] [Nested Loops] Q45: Write a python program to print the Following: 1 2 1 3 2 1

Q46: WAP to print the following asterisk pattern: image

Q47: WAP to create a function traiangle to print the following asterisk triangle pattern: image

Q48: Write a python program to print following multiplication table on the screen image

Q49: write a Program to display the Fibonacci sequence up to n-th term where n is provided by the user

Q50: Write a Python Program to Display Powers of 2 Using Anonymous Function
( Lambda function). Take number of terms from user

Q51: Write a Python Program to find numbers divisible by thirteen from a list using anonymous function

Q52: Write a Python program to display the Fibonacci sequence up to n-th term by using recursive functions

Q53: Write a Python program to find the sum of natural numbers up to n using recursive function

Q54: Write a Python program to convert decimal number into binary number using recursive function

Lab Exercises 5 (Based on Modules, Packages & File handling)

Q55. Write a Python program to read an entire text file.

Q56. Write a program that counts lines and characters in a file. With your favorite text editor, code a Python module called mymod.py, which exports three top-level names: a) A countLines(name) function that reads an input file and counts the number of lines in it b) A countChars(name) function that reads an input file and counts the number of characters in it c) A test(name) function that calls both counting functions with a given input filename. All three mymod functions should expect a filename string to be passed in. Now, test your module interactively, using import and name qualification to fetch your exports.

Q57. Test your mymod module from Exercise 2 interactively, by using from to load the exports directly, first by name, then using the from* variant to fetch everything.

Q58. Now, add a line in your mymod module that calls the test function automatically only when the module is run as a script, not when it is imported The line you add will probably test the value of name for the string "main", as shown in this unit. Try running your module from the system command line; then, import the module and test its functions interactively.

Q59. Write a second module, myclient.py, which imports mymod and tests its functions; run myclient from the system command line. If myclient uses from to fetch from mymod, will mymod’s functions be accessible from the top level of myclient? What if it imports with import instead? Try coding both variations in myclient and test interactively, by importing myclient .

Q60. Package imports. Finally, import your file from a package. Create a subdirectory called mypkg nested in a directory on your module import search path, move the mymod.py module file you created in exercises 2 or 4 into the new directory, and try to import it with a package import of the form: import mypkg.mymod.

Q61. Experiment with module reloads: perform the tests in the changer.py example, changing the called function’s message and/or behavior repeatedly, without stopping the Python interpreter. Depending on your system, you might be able to edit changer in another window.

Lab Exercise 7

Q62. Write a Python program to read first n lines of a file.

Q63. Write a Python program to append text to a file and display the text.

Q64. Write a Python program to read a file line by line and store it into a list.

Q65. Write a program to print each line of a file in reverse order.

Q66. Write a Python program to write a list content to a file.

Q67. Write a program to compute the number of characters, words and lines in a file.

Q68: Subtract a week ( 7 days) from a given date in Python

Q69: Add week ( 7 days) and 12 hours to a given date Given: 2020-03-22 10:00:00 given_date = datetime(2020, 3, 22, 10, 0, 0) Expected output: 2020-03-29 22:00:00

Q70: Print ten dates, each two a week apart, starting from today, in the form YYYY-MM-DD.

Q71: Calculate number of days between two given dates Given: 2020-02-25 date_1 = datetime(2020, 2, 25) 2020-09-17 date_2 = datetime(2020, 9, 17) Expected output: 205 days

Q72: Write a Python script to display the a) Current date and time b) Current year in full c) Month of year full name d) Weekday of the week e) Day of year f) Day of the month g) Day of week in full name

Q73: Python program to convert a string to datetime: 'Jul 1 2016 2:43AM' into 2016-07-01 02:43:00

Q74: Python program to convert Year/Month/Day to Day of Year.

Lab Exercise 8: Q75: Follow the steps: • Create a class, Triangle. Its init() method should take self, angle1, angle2, and angle3 as arguments. Make sure to set these appropriately in the body of the init()method. • Create a variable named number_of_sides and set it equal to 3. • Create a method named check_angles. The sum of a triangle's three angles is It should return True if the sum of self.angle1, self.angle2, and self.angle3 is equal 180, and False otherwise. • Create a variable named my_triangle and set it equal to a new instance of your Triangle class. Pass it three angles that sum to 180 (e.g. 90, 30, 60). • Print out my_triangle.number_of_sides and print out my_triangle.check_angles().

Q76: Define a class called Songs, it will show the lyrics of a song. Its init() method should have two arguments:self and lyrics.lyricsis a list. Inside your class create a method called sing_me_a_song that prints each element of lyricson his own line. Define a varible: happy_bday = Song(["May god bless you, ", "Have a sunshine on you,", "Happy Birthday to you !"]) Call the sing_me_song method on this variable.

Q77: Define a class called Lunch.Its init() method should have two arguments:selfanf menu.Where menu is a string. Add a method called menu_price.It will involve a ifstatement: • if "menu 1" print "Your choice:", menu, "Price 12.00", if "menu 2" print "Your choice:", menu, "Price 13.40", else print "Error in menu". To check if it works define: Paul=Lunch("menu 1") and call Paul.menu_price().

Q78: Write a Python class which has two methods get_String and print_String. get_String accept a string from the user and print_String print the string in upper case.

Q79: Write a program to find the area and perimeter of a rectangle using classes and objects. Program output should be like this: image

Lab Exercise 9

Q80. Define a class to represent a bank account. Include the following members: Data Members: a.Name of the Depositor b.Account Number c.Type of Account d.Balance amount in the account Data Methods: a.To assign initial values b.To deposit an amount c.To withdraw an amount d.To display name and balance.

Output:

  1. New customer
  2. Deposit
  3. Withdrawal
  4. Display
  5. Exit

Q81. Write a program to implement following. Create a base class named person consisting of name and code. Create 2 child classes a) Account with member_pay b) Admin with experience and inherit the base class.

Create a class employee with name, code, experience and pay by inheriting the above classes.

Q82. Write program to create a base class staff with code and name. Derive classes teacher(subject , publication) , typist (speed) , officer (grade) . Using the typist class as base class,create two classes regular(salary) and casual(daily wages).Implement a menu driven program for the same.

Output:

  1. Teacher
  2. Officer,
  3. Regular Typist
  4. Casaul typist
  5. Exit

Lab Exercise - 10:

Q83: Write a function to compute 5/0 and use try/except to catch the exceptions.

Q84: Write a Python program to access the array element whose index is out of bound and handle the corresponding exception

Q85: Write a Python Program to handle multiple errors with one except statement

Q86: Write a Python Program to depict else clause with try-except

Q87: Write a Python Program to depict Raising Exception

Q88: Write a python program to create user-defined exception

Q89: Print one message if the try block raises a NameError and another for other errors:

Q90: Try to open and write to a file that is not writable:

Q91: Write a python program to raise an error and stop the program if x is lower than 0.

Q92: Write a python program to raise a TypeError if x is not an integer:

Lab Exercise 11 – (regex)

Q93: Write a Python program that matches a string that has an a followed by zero or more b's.

Q94: Write a Python program to check for a number at the end of a string.

Q95 : Write a Python program to search some literals strings in a string.

Q96: Replace all occurrences of 5 with five for the given string i.e. 'They ate 5 apples and 5 oranges' .

Q97: Replace all occurrences of note irrespective of case with X in given string i.e. 'This note should not be NoTeD'.

Q98: Write a Python program to remove leading zeros from an IP address. For example: IP Address 216.08.094.196 should be represented as 216.8.94.196

Q99.Write a program to create a version of a palindrome recognizer that also accepts phrase palindromes such as "Go hanga salami I'm a lasagna hog.", "Was it a rat I saw?", "Step on no pets", "Sit on a potato pan, Otis", "LisaBonet ate no basil", "Satan, oscillate my metallic sonatas", "I roamed under it as a tired nude Maori","Rise to vote sir", or the exclamation "Dammit, I'm mad!". Note that punctuation, capitalization, and spacing are usually ignored.

Q100.In cryptography, a Caesar cipher is a very simple encryption techniques in which each letter in theplain text is replaced by a letter some fixed number of positions down the alphabet. For example, with ashift of 3, A would be replaced by D, B would become E, and so on. The method is named after JuliusCaesar, who used it to communicate with his generals. ROT-13 ("rotate by 13 places") is a widely usedexample of a Caesar cipher where the shift is 13. In Python, the key for ROT-13 may be represented bymeans of the following dictionary:key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b','p':'c', 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k', 'y':'l', 'z':'m', 'A':'N', 'B':'O', 'C':'P', 'D':'Q', 'E':'R','F':'S', 'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A', 'O':'B', 'P':'C', 'Q':'D', 'R':'E', 'S':'F', 'T':'G','U':'H', 'V':'I', 'W':'J', 'X':'K', 'Y':'L', 'Z':'M'}Your task in this exercise is to implement an encoder/decoder of ROT-13. Once you're done, you will beable to read the following secret message:Pnrfne pvcure? V zhpu cersre Pnrfne fnynq!Note that since English has 26 characters, your ROT-13 program will be able to both encode and decodetexts written in English.

Q101. Untitled

About

Repository of all Assigments of Advanced Python Programming of CDAC PG-DAI Course

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages