Assignment 2: Set No. Roll No
Assignment 2: Set No. Roll No
Assignment 2: Set No. Roll No
Max. Marks 30
Instructions:
2. Write a program that has dictionary of names of five cricketers and a list of their runs in
5 matches. Create another dictionary from this dictionary that has name of the students
and their total runs (sum of all runs). Find out the player with maximum number of runs.
Sample: players= {“Dhoni: [20,45,67,78,80],…………………………}
OUTPUT: New_players = {“Dhoni”:[290],…………………………………………………… }
Dhoni with highest runs=290
3. Write a program to read a name and the displays it in abbreviated form e.g Dev Karan
Singh should be displayed as
(a) D.K. Singh.
Set 2
1. Write a program to generate and print all possible combinations of the characters present
in a given string. Take length of string = 4 e.g. JOHN will have combinations
JONH, JNOH…………
2. Write a program that reads in numbers separated by a space in one line and displays
distinct numbers (i.e., if a number appears multiple times, it is displayed only once). (Hint:
Read all the numbers and store them in list1. Create a new list list2. Add a number in list1
to list2. If the number is already in the list, ignore it.)
3. Write a program that displays a menu and its price. Take the order from the customer.
Check if the ordered product is in the menu. In case it is not there, the customer should
be asked to reorder and if it is present, then product should be added in the bill.
Print the final bill.
Set 3
1. Write a program that receives an integer (less than or equal to nine digits in length) and
prints out the number in words. For example, if the number input is 12342, then the
output should be Twelve Thousand Three Hundred Forty-Two.
2. Write a program that has a dictionary of your friends’ name (as keys) and their birthdays.
Print the items in the dictionary in a sorted order. Prompt user to enter the name and
check if it is present in the dictionary. If the name does not exist, then ask the user to
enter DOB.Add the details in the dictionary.
3. Develop a function in Python which takes an English word as input and returns its
antonym word. Find suitable data structure for this program and implement. (TAKE 10
WORDS)
Set 4
1. Write a hangman game that randomly generates a word and prompts the user to
guess one letter at a time, as shown in the sample run. Each letter in the word is
displayed as an asterisk. When the user makes a correct guess, the actual letter is then
displayed. When the user finishes a word, display the number of misses and ask the
user whether to continue playing. Create a list to store the words, as follows: # Use
any words you wish
3. Write a function that accepts two positive numbers n and m where m<=n, and
returns numbers between 1 and n that are divisible by m.
Set 5
1. (Check password) Some Web sites impose certain rules for passwords. Write a function
that checks whether a string is a valid password. Suppose the password
rules are as follows:
■ A password must have at least eight characters.
■ A password must consist of letters, digits and underscore.
■ A password must contain at least two digits.
Write a program that prompts the user to enter a password and displays valid
2.Write a program to create a list of randomly generated numbers in the range 0-99. Then
delete all the numbers from the list that are divisible by 3 and convert all the left numbers into
a single digit. E.g 77 = 7+7=14=1+5=5
3. Write a Python program to find maximum length of consecutive 0's in a given binary string
where:
*
***
*****
*******
*********
*****
*****
*****
*****
2. Define a python function ‘australian_tennis(d)’ which reads a dictionary of the
following form and identifies the player with the highest total score. The function
should return a pair (playername, topscore), where playername is the name of the
player with the highest score and topscore is the total runs scored by the player.
Input is:
australian_tennis ({‘test1’:{‘Samantha Stosur:7, ‘Astra Sharma:8}, {‘test2’:{ Astra
Sharma: 5, ‘Ellen Perez: 4}})
3. Write a program to calculate the parking charges of a vehicle. Enter the type of
vehicle as a character (like c for car, b for bus, etc.) and read the hours and minutes
when the vehicle enters the parking lot. When the vehicle is leaving, enters its
leaving time. Calculate the difference between the two timings to calculate the
number of hours and minutes for which the vehicle was parked. Calculate the
charges based on the following information:
2.) . Write a program to record the details of books in a library (e.g., Book Title, Book
ID, Author(s), etc.) in a dictionary as follows:
Books = {(Book ID, Book Title): (Subject, Author(s), Edition, Publisher, etc.),
……………….}
Arrange the books in a sorted order corresponding to their respective author
names.
3.) Create a list with first name for 5 person as FN= [“rahul”, “ram”,………]
Second list with last name as LN= [“sharma”,”Kapoor”,……..]
In output
New List as NL= [“RS”,RK”,…..]