HHW CS Xii
HHW CS Xii
Instructions:
• There are 20 programs in this assignment.
• Write code for one or two programs daily in order to finish the assignment on time.
• Create a word file and paste the code as well as snap shot of output for each program.
STRING PROGRAMS
Q1 Write a program to input a string STR and display the words of STR with a hyphen in
between.
For instance, if the input string is : “Nile is the longest river in the world”
Then the output should be:
Nile-is-the-longest-river-in-the-world
Q2 Input a string and display the word with longest length. For example, if string is “Wular
is largest freshwater lake in India”
Then the output should be freshwater.
Q3 Write a program to input a string and print the number of words containing atleast on
vowel
For instance, if the input string is : “Sky is Blue”
Then the output should be 2
Q4 Input a string and replace every third character of this string by an asterisk *
For instance, if the string is “RIVER AMAZON”, then the output should be:
RI*ER*AM*ZO*
Q5 Input a string and check whether it is a binary string or not. (A binary string contains only
0’s and 1’s.
Q6 Write a function E2(S1) in Python which takes string S1 as parameter and displays all the
words containing at least two e’s.
Example: If the string S1 is:
An apple a day keeps the doctor away. Writing two programs daily will make a
difference.
Then E2() function should display the output as: keeps difference.
Q7 Write a program to input a string and display count of words with atmost one vowel in
it. For instance if the input string is : Sky is blue and the weather is dry
Then output should be;
The number of words with atmost one vowel : 6
Q11 Write a program to input a word. Create a dictionary, where the keys of the dictionary
are the letters of the word and values of the dictionary is the frequency of each letter in
that word. For example, if the word is: MISSISIPPI, then dictionary should be:
D={‘M’: 1, ‘I’: 4, ‘S’: 3, ‘P’: 2}
LIST PROGRAMS
Q12 Write a program to input a list of integers. After taking input, adjust the elements of this
list so that all even numbers are in the beginning of the list and odd numbers are
towards the end. For instance, if the input list is:
L=[3,2,4,5,18,20,27, 6]
Then the resultant list should be:
L=[2,4,18,20,6, 3,5,27]
Q13 Write the definition of the function INDICES(L) that takes a list L as parameter and returns
another list named L2 that stores the indices of all even numbers of L.
For example:
If L contains [12,4,3,11,13,56]
The L2 will contain : [0,1,5]
Q14 Write a program to declare a list of integers. Display the sum of even and odd numbers
separately. for example:
Given list
L=[1,2,3,4,5,6]
Output:
Sum of even numbers is: 12
Sum of odd numbers is: 9
Q15 Write a program to declare a list of integers and find the sum of multiples of 3.
Q16 Write a program to input a list of integers from the user and multiply the numbers at
odd index by 2. For example, if the List L is [2,10,3,20,4,40],
then the resultant list should be
[2, 20, 3, 40, 4, 80]
Q17 Write a program that declares a list of integers NUM and increments the odd numbers
by 1 and decrements the even numbers by 2 in the original list. For instance if NUM
=[15,3,7,2,6,1]
Then the resultant list would be NUM= [16, 4, 8, 0, 4, 2]
Q18 Write the definition of a function FunWithDigits(L) which accepts a list of strings L as
parameter and displays only those strings which contain atleast one digit in them
For example if the List L is [“Seat2, “1VIP” , “11”, “two”]
Then the output should be
Seat2
1VIP
11
Q19 Write a program to declare a list of integers and swap the adjacent elements of this list.
For instance, if the given list L=[20,30,40,50,60,70]
Then the resultant list should be L=[30,20,50,40,70,60]
Q20 Write a function shiftn(L,n), where L is a list of integers and n is an integer. The function
should return a list after shifting n number of elements to the left.
Example: If the list initially contains [2, 15, 3, 14, 7, 9, 19, 6, 1, 10] and n=2
then function should return [3, 14, 7, 9, 19, 6, 1, 10, 2, 15]
If the list initially contains [2, 15, 3, 14, 7, 9, 19, 6, 1, 10] and n=4
then function should return [7, 9, 19, 6, 1, 10, 2, 15, 3, 14]