Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8415887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:34:41+00:00 2026-06-10T01:34:41+00:00

I’m trying to create a secret coding program but am having trouble with for

  • 0

I’m trying to create a secret coding program but am having trouble with for loops (I’ve never really understood them). Here is what I have to far, I’m trying to get the users input, the convert each word of the users text into the coded text, so if someone types in “hello”, it will become “vpyyl”. Can someone please help? Is this even possible?

This is what I have so far, it’s giving an error “list indices must be integers, not str”. I’m pretty sure the for loop is set up wrong as well.

import random

list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
codedList = ['s', 'q', 'n', 'z', 'p', 'o', 'k', 'v', 'm', 'c', 'i', 'y', 'w', 'a', 'l', 't', 'd', 'r', 'j', 'b', 'f', 'e', 'h', 'u', 'x', 'g']

text = input("Enter your text: ")

for i in [text]:
    i = codedList[i]
    print[i]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:34:43+00:00Added an answer on June 10, 2026 at 1:34 am

    There’s only one item in [text]: the whole string that was entered by the user. You probably want for i in text: which will set i to each character of the string.

    Also, you’ve named a list list (which means you’ve lost access to the built-in name list). And lists are indexed by integers, while you’re trying to access the elements with a string. You probably want to use a dictionary for that, mapping each letter to its coded equivalent.

    A couple of other problems are that you don’t have any code to handle situations in which something other than a letter is entered (spaces, punctuation) and the letters are all lowercase. Finally, you’re using square brackets in your print call instead of parentheses, and you’re not suppressing line breaks.

    So:

    code = dict(a='s', b='q', c='n', d='z', e='p', f='o', g='k', h='v', i='m', j='c',
                k='i', l='y', m='w', n='a', o='l', p='t', q='d', r='r', s='j', t='b',
                u='f', v='e', w='h', x='u', y='x', z='g')
    
    # another way to define the dictionary (you don't need both)
    alphabet      = "abcdefghijklmnopqrstuvwxyz"
    codedalphabet = "sqnzpokvmciywaltdrjbfehuxg"
    code          = dict(zip(alphabet, codedalphabet))
    
    # add upper-case versions of all letters to dictionary
    for letter, codedletter in code.iteritems():
        code[letter.upper()] = codedletter.upper()
    
    for char in input("Enter your text: "):
        if char in code:
            print(code[char], end="")
        else:
            print(char, end="")    # not an alphabetic character, print as-is
    print()                        # we haven't printed a line break; do so now
    

    As others have noted, there are some things built into Python that can make this trivial, but if you’re having trouble with for loops, that won’t help you learn. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.