Write a program that uses exactly four for loops to print the sequence of letters below.
AAAAAAAAAABBBBBBBCDCDCDCDEFFFFFFG
for i in range(10):
print("A", end='')
for i in range(7):
print("B", end='')
for i in range(3):
print("CD", end='')
print("D", end='')
for i in range(5):
print("E", end='')
for i in range(6):
print("F", end='')
print("G", end='')
This code will use for
loops to iterate over the specified number of times and print the appropriate letter. The end=''
parameter in the print()
function will prevent the letter from being printed on a new line, so all the letters will be printed on the same line.
To run this code, you can save it to a file with a .py
extension and run it using the python
command in a terminal or command prompt.
0 Comments