Computer Science
Create a tuple ('a', 'bb', 'ccc', 'dddd', … ) that ends with 26 copies of the letter z using a for loop.
Answer
tup = ()
for i in range(1, 27):
tup = tup + (chr(i + 96)* i,)
print(tup)
Output
('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')
Related Questions
Write a program as per following specification :
"'Return the length of the shortest string in the tuple of strings str_tuple.
Precondition: the tuple will contain at least one element."'Create a tuple containing the squares of the integers 1 through 50 using a for loop.
Given a tuple pairs = ((2, 5), (4, 2), (9, 8), (12, 10)), count the number of pairs (a, b) such that both a and b are even.
Write a program that inputs two tuples seq_a and seq_b and prints True if every element in seq_a is also an element of seq_b, else prints False.