#๐ need help with combination number to letter code
9 messages ยท Page 1 of 1 (latest)
@stable vector
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Define a dictionary to map digits to their corresponding letters
digit_to_letters = {
'2': 'ABC',
'3': 'DEF',
'4': 'GHI',
'5': 'JKL',
'6': 'MNO',
'7': 'PRS',
'8': 'TUV',
'9': 'WXY'
}
This loop will keep running until the user decides to stop
while True:
# Get the phone number from the user
phone_number = input("Enter a 7-digit phone number (no 0s or 1s), or type 'quit' to exit: ")
# Check if the user wants to quit
if phone_number.lower() == 'quit':
break
# Check if the phone number is valid (only contains digits 2-9 and is exactly 7 digits)
if len(phone_number) != 7 or not all(digit in digit_to_letters for digit in phone_number):
print("Invalid phone number. Please enter a 7-digit number using only digits 2-9.")
else:
# Initialize a counter for the combinations
combination_count = 0
# Generate all possible word combinations in reverse order
print("Possible word combinations:")
for letter7 in digit_to_letters[phone_number[6]]:
for letter6 in digit_to_letters[phone_number[5]]:
for letter5 in digit_to_letters[phone_number[4]]:
for letter4 in digit_to_letters[phone_number[3]]:
for letter3 in digit_to_letters[phone_number[2]]:
for letter2 in digit_to_letters[phone_number[1]]:
for letter1 in digit_to_letters[phone_number[0]]:
print(letter1 + letter2 + letter3 + letter4 + letter5 + letter6 + letter7)
combination_count += 1
# Print the total number of combinations
print(f"A total of **{combination_count}** combinations were generated.")
Hey @stable vector!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
i expect it show all 2187 combinations but it doesnt show any with other letters for the last digit
so something like having a 2 at the end would only show c but not any combinations with a or b
'''py
print('Hello, world!')
'''
darn
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.