Tuples || Sumita Arora || Class 11 || Practical || Computer Science || Solution

 

P.I.P:- 8.1


Q1. Create a tuple names as given here:
names = ('Bobby', 'Hoshiar', 'Ekta', 'Astha', 'Dave', 'Lily')

For the following steps, use names and slice notation:
(a) Write an expression that produces this new tuple: ('Ekta', 'Asthu', 'Dare')
(b) Write an expression that produces this new tuple: ('Bobby')
(c) Write an expression that produces this new tuple: ('Astha', 'Dave', 'Lily')




Q2. Write an expression that adds the string "How are you?" to the front of all the elements of the tuple ('I am fine, thank you')

and creates a new tuple out of it.




Q3. Write a program that inputs a tuple and creates a new tuple that contains every third element of the original tuple, starting

at index 0. Don't use slice notation. Write code using a for loop.






Use while loops to complete the following functions (Q.4 to Q.6) (Do not use for loops)



Q4. Write a program to print the alternate elements of a tuple T.



Q5. Write a program to print every 3rd element of a tuple T, raised to power 3.



Q6. Write a program that inputs a tuple having words of a string as its elements e.g., ("The", "quick", "brown", "fox") and then

translates each text element to Pig Latin.

[English is translated to Pig Latin by taking the first letter of every word, moving it to the end of the word and adding "ay".

"The quick brown fox" becomes "Hetay uickqay rownbay oxfay".]




Q7. Write a program that takes a tuple with words in Pig Latin (as created by previous question) and translates it back to

original text.




Q8. Write the code as per following specifications. You may use for loops.

(a) Write a loop that prints each inner tuple from tuple pets on a separate line.
(b) Write a loop that prints the second element of each inner tuple in tuple pets on a separate line.
(c) Write a loop that examines tuple pets and computes the number of dogs in the tuple.
(d) Write a loop that examines tuple pets and computes the sum of the ages of the animals in the tuple. Ages are the third

element of the inner tuples.
(e) Write a program that inputs a tuple T and prints a tuple of the lengths subtuples.

For example, if passed tuple T is
((1, 2), (2, 4, 6), (4,), (5, 0, 5))
Then it should prints (2, 3, 1, 3)

(f) Write a program that inputs a tuple with each element of it as another tuple. It then prints the elements of the tuple in

increasing order of their lengths.




Q9. Write a program that inputs a number n (integer) and creates a tuple containing: n, 2n, 3n and 4n.

 

 

10 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post