Assignment_Based_on_Looping_and_Data_Structures_in_Python
Assignment_Based_on_Looping_and_Data_Structures_in_Python
Question 1
Create the following using a 2D dictionary showing the sales each person has made in the different geographical
regions:
Ask the user for a name and a region. Display the relevant data. Ask the user for the name and region of data
they want to change and allow them to make the alteration to the sales figure. Display the sales for all regions
for the name they choose.
Question 2
Ask the user to enter the name, age and shoe size for four people.
• Ask for the name of one of the people in the list and display their age and shoe size.
• Display the names and ages of all the people in the list but do not show their shoe size.
• After gathering the four names, ages and shoe sizes, ask the user to enter the name of the person they
want to remove from the list. Delete this row from the data and display the other rows on separate
lines.
Question 3
Ask the user to enter a number between 10 and 20. If they enter a value under 10, display the message “Too
low” and ask them to try again. If they enter a value above 20, display the message “Too high” and ask them to
try again. Keep repeating this until they enter a value that is between 10 and 20 and then display the message
“Thank you”.
Question 4
Ask the user for a number and determine whether the number is prime or not. (For those who have forgotten, a
prime number is a number that has no divisors.).
Question 5
Create a dictionary of names and birthdays of Indian Prime Ministers. When you run your program it should ask
the user to enter a name of the Prime Minister, and return the birthday.
Date of birth : Name of Prime Minister
14 November 1889 : Jawaharlal Nehru
29 February 1896 : Morarji Desai
4 July 1898 : Gulzarilal Nanda
23 December 1902 : Charan Singh
2 October 1904: Lal Bahadur Shastri
19 November 1917 Indira Gandhi
4 December 1919 Inder Kumar Gujral
28 June 1921 P. V. Narasimha Rao
25 December 1924 Atal Bihari Vajpayee
1 July 1927 Chandra Shekhar
25 June 1931 Vishwanath Pratap Singh
26 September 1932 Manmohan Singh
Question 6:
With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an
integral number between 1 and n (both included). and then the program should print the dictionary.
Suppose the following input is supplied to the program:
8
Then, the output should be:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
Then accept any integer in the range of 1 to n and display its square by fetching its value from the dictionary and
continue the process till the user wishes to continue.
Question 7:
Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters.
Suppose the following input is supplied to the program: Hello world! Then, the output should be: UPPER CASE 1
LOWER CASE 9
Question 8:
You are required to write a program to sort the (name, age, height) tuples by ascending order where name is
string, age and height are numbers. The tuples are input by console.
The sort criteria is:
1: Sort based on name;
2: Then sort based on age;
3: Then sort by score.
The priority is that name > age > score.
If the following tuples are given as input to the program:
Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Json,21,85
Then, the output of the program should be:
[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21',
'85'), ('Tom', '19', '80')]