Click here to Skip to main content
15,904,638 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
#read the list of words from the file
#store the list of words in a python list
#take phone number as input from user
number=input('Enter an 8-digit number\n')
#store the keypad letters in key-letters format
#extract the last four digits of phone number for translation
#temporary list to store possible translations for given number
#list i initially a copy of original words_list provided
for i in last_four:
    #if number can no more get translated
    if i not in letters.keys():
        print('Translation failed')
    #check for the possible combinations stepwise for each number in sequence
    for j in range(len(letters[i])):
        for word in prev_list:
            if word[k]==temp:
    #if no more translations can be obtained
    if not prev_list:
        print('Translation failed')
    #if there are possible translations print them all
    for i in prev_list:

What I have tried:

I have tried reading it and converting it but I have no experience with python, I only know C, please can someone help and convert it for me.
Updated 24-Feb-23 4:15am

This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.

And frankly? If you blindly convert from any language into C and hand it is as your own work then two things will happen:
1) You will learn nothing about how to write C code, and will real problems when you either reach a task you can't find (and it'll be more complicated that this task), or reach your exams and can't copy from anywhere ...
2) It'll be blindingly obvious to your tutor what you did (and probably the language you found it in) and you could get an automatic course fail for plagiarism.

I'd think long and hard about your whole homework solving method, if I was you ...
Share this answer
CPallini 7-Apr-22 2:03am    
The main logic is quite easy to figure out even without knowing Python. The missing bit about String slicing is explained at 3. An Informal Introduction to Python — 3.1.2. Strings[^] and the following section on Lists.
Share this answer
CPallini 7-Apr-22 2:03am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900