Skip to content

DRASHHTIPATEL/PROGRAMMING-_IN-PYTHON_CE259

Repository files navigation

PROGRAMMING-_IN-PYTHON_CE259

practical2

Dictionary

a. Write a Python script to check whether a given key already exists in a dictionary.

b. Write a Python script to merge two Python dictionaries.

c. Write a Python program to sum all the items in a dictionary.

d. Write a Python script to add a key to a dictionary.

Sample Dictionary : {0: 10, 1: 20}

Expected Result : {0: 10, 1: 20, 2: 30}

e. Write a Python script to concatenate the 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}

Set

a. Write a Python program to add member(s) in a set and clear a set

1,2

b. Write a Python program to remove an item from a set if it is present in the set.

c. Write a Python program to create an intersection, Union, difference of sets.

d. Write a Python program to find maximum and the minimum value in a set.

  1. Write a Python program to find the most common elements and their counts from list, tuple, dictionary.

Tuple

a. Write a Python program to create a tuple with different data types.

b. Write a Python program to create a tuple with numbers and print one item.

c. Write a Python program to add an item in a tuple.

d. Write a Python program to convert a tuple to a string.

e. Write a Python program to find the length of a tuple.

practical 3.Find Captain Room Number

Sample Input

5

1 2 3 6 5 4 4 2 5 3 6 1 6 5 3 2 4 1 2 5 1 4 3 6 8 4 3 1 5 6 2

Sample Output

8

Explanation: The list of room numbers contains 31 elements. Since K is 5, there must be 6 groups of families. In the given list, all of the numbers repeat 5 times except for room number 8.

Hence, 8 is the Captain's room number.

1,2

practical 4. Find runner-up from given list

Sample Input 5 2 3 6 6 5

Sample Output 5 Explanation: Given list is [2,3,6,6,5]. The maximum score is 6, second maximum is 5. Hence, we print 5 as the runner-up score.

1,2

practical 5. You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa . Sample Input: HackerRank.com presents "Pythonist 2" . Sample Output: hACKERrANK.COM PRESENTS "pYTHONIST 2".

practical 6 You are given n words. Some words may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification. Sample Input 4 bcdef abcdefg bcde bcdef Sample Output 3 2 1 1 Explanation: There are 3 distinct words. Here, "bcdef" appears twice in the input at the first and last positions. The other words appear once each. The order of the first appearances are "bcdef", "abcdefg" and "bcde" which corresponds to the output.

practical 7 Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each cha odd number of characters in the string, we ignore the middle character and check for racter. If there 1,2 Page 3 of 3 are lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccab, rotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match. Your task is simple. Given a string, you need to tell if it is a lapindrome

practical 8 Write a Program in Python to implement a Stack Data Structure using Class and Objects, with push, pop, and traversal method.

practical 9 Consider an example of declaring the examination result. Design three classes: Student, Exam, and Result. The Student class has data members such as those representing rollNumber, Name, etc. Create the class Exam by inheriting Student class. The Exam class adds fields representing the marks scored in six subjects. Derive Result from the Exam class, and it has its own fields such as total_marks. Write an interactive program to model this relationship.

practical 10 Generate PDF file of your 3rd Semester Mark-sheet

About

Practical 2: Study and Learn List, Tuple, Set and Dictionary

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages