Nested loops - Two character dotcom domain names

Modify the program to include two-character .com names, where the second character can be a letter or a number, e.g., a2. com. Hint: Add a second while loop nested in the outer loop, but following the first inner loop, that iterates through the numbers 0-9.

‘’’
Program to print all 2-letter domain names.
Note that ord() and chr() convert between text and ASCII/ Unicode encodings.
ord(‘a’) is 97. ord(‘b’) is 98, and so on. chr(99) is ‘c’, etc.
‘’’
print(‘Two-letter domain names:’)

letter1 = ‘a’
letter2 = ‘?’
while letter1 <= ‘z’: # Outer loop
letter2 = ‘a’
while letter2 <= ‘z’: # Inner loop
print(‘{}{}.com’.format(letter1, letter2))
letter2 = chr(ord(letter2) + 1)
letter1 = chr(ord(letter1) + 1)
for letter2 in range(10): # Part I added
print(‘{}{}.com’.format(letter1, letter2))
letter1 = chr(ord(letter1) + 1)

When I run the program it skips A1, A2…C1, C2…etc. I don’t know how to fix it.

I believe this is the solution they want… (using - to indicate spaces)

print(‘Two-letter domain names:’)

letter1 = ‘a’
letter2 = ‘?’
while letter1 <= ‘z’: # Outer loop
----letter2 = ‘a’
----while letter2 <= ‘z’: # Inner loop
--------print(‘{}{}.com’.format(letter1, letter2))
--------letter2 = chr(ord(letter2) + 1)
----letter2 = 0
----while letter2 <= 9:
--------print(‘{}{}.com’.format(letter1, letter2))
--------letter2 += 1
----letter1 = chr(ord(letter1) + 1)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.