Q. Create the following tuple using a for loop :

(i) A tuple containing the squares of the integer 1 though 50.

(ii) The tuple (“a”, “bb”, “ccc”….)that ends with 26 copies of the letter z.


You can understand by Watching video :-



Answer :-

(i)

tup = ()
for i in range(1,51):
    tup = tup + ( i**2,)
print(tup)

(ii)

tup = ()
for i in range(1 , 27):
    tup = tup + ( chr(i + 96 )* i ,)
print(tup)

Output :-

(i)

(1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500)
>>>

(ii)

('a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff', 'ggggggg', 'hhhhhhhh', 'iiiiiiiii', 'jjjjjjjjjj', 'kkkkkkkkkkk', 'llllllllllll', 'mmmmmmmmmmmmm', 'nnnnnnnnnnnnnn', 'ooooooooooooooo', 'pppppppppppppppp', 'qqqqqqqqqqqqqqqqq', 'rrrrrrrrrrrrrrrrrr', 'sssssssssssssssssss', 'tttttttttttttttttttt', 'uuuuuuuuuuuuuuuuuuuuu', 'vvvvvvvvvvvvvvvvvvvvvv', 'wwwwwwwwwwwwwwwwwwwwwww', 'xxxxxxxxxxxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzzzzzzzzzzzz')
>>> 


9 Comments

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

  1. in the second code it should be 97 instead of 96

    ReplyDelete
  2. it was correct, it is supposed to be 96 only instead of 97. I Checked it.

    ReplyDelete
  3. thank you so much for helping out, really greateful<3

    ReplyDelete
  4. First one is wrong, it's asking to print the squares of numbers not the numbers. It should be
    For i in range (1,51):
    a=(i)**2
    tup= tup + (a,)
    print (tup)

    ReplyDelete

Post a Comment

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

Previous Post Next Post