Having a hard time with 'For' Loops

having a hard time synonym
give someone a hard time meaning
i'm going through a very difficult time in my life
hard time meaning in hindi
how to get through hard times in life
hard time meaning in tamil
hard time for all of us
going through tough times

I am new to Python and learning about 'For' loops. What I am trying to do is use a for loop to go through some letters I set in a variable then print specific letters to make a message.

I have gotten multiple errors with basically everything I do and I am now just looking for an example of how to do it the right way.

currentpos = 0
unenckey = ['a', 'e', 'f', 'h', 'i', 'k', 'm', 'o', 'r', 's', 't', 'w']
enc = "ztxhcccczxbatnnsqhlllowqtdhdzxveqmvbanmfxzibbaqwojrdkls"
for unenc in enc: 
    while True:
        if unenc == unenckey[currentpos]:
            currentpos = 0
            print(unenc)
            break
        elif unenc == 'q':
            print(' ')
            break
        else:
            if currentpos == 11:
                currentpos = 0
            if currentpos != 11:
                currentpos = currentpos + 1
                continue

It just goes on forever and I am not sure what to do.

Your inner loop got stuck on characters which are not found because you never used a break on reaching currentpos ==11. You had most of the logic figured out spot on. Just fixing that ends up with the following:

currentpos = 0
unenckey = ['a', 'e', 'f', 'h', 'i', 'k', 'm', 'o', 'r', 's', 't', 'w']
enc = "ztxhcccczxbatnnsqhlllowqtdhdzxveqmvbanmfxzibbaqwojrdkls"
for unenc in enc: 
    while True:
        if unenc == unenckey[currentpos]:
            currentpos = 0
            print(unenc)
            break
        elif unenc == 'q':
            print(' ')
            break
        else:
            if currentpos == 11:
                currentpos = 0
                break #modified
            if currentpos != 11:
                currentpos = currentpos + 1
                continue

I'm afraid the "mamfia" doesn't quite work that way though. Alas. :)

As you get more comfortable with the basic structure, you can use some of the power of python in the in operator to check if each letter exists in the unenckey directly.

unenckey = ['a', 'e', 'f', 'h', 'i', 'k', 'm', 'o', 'r', 's', 't', 'w']
enc = "ztxhcccczxbatnnsqhlllowqtdhdzxveqmvbanmfxzibbaqwojrdkls"
for unenc in enc:
    if unenc == 'q':
        print(' ')
    elif unenc in unenckey:
        print(unenc)
    else:
        pass

I'm having a hard time + (verb-ing), By stating you are having a hard time you are letting someone know you are having difficulty with something. This could be something physical or mental and​  Definition of have a hard time : to experience difficulty doing something She's having a hard time living within her budget. The school has had a hard time recruiting substitute teachers. He's been having a hard time with his research paper.

You just have to remove the while loop. You've put while True, so that's what causes it to go on forever. Change it to this:

currentpos = 0
unenckey = ['a', 'e', 'f', 'h', 'i', 'k', 'm', 'o', 'r', 's', 't', 'w']
enc = "ztxhcccczxbatnnsqhlllowqtdhdzxveqmvbanmfxzibbaqwojrdkls"
for unenc in enc:
    if unenc == unenckey[currentpos]:
        currentpos = 0
        print(unenc)
        break
    elif unenc == 'q':
        print(' ')
        break
    else:
        if currentpos == 11:
            currentpos = 0
        if currentpos != 11:
            currentpos = currentpos + 1
            continue

10 Simple Things You Can Do To Get Through Hard Times, when you can better navigate the difficult times, you not only live a happier life, but you'll also grow as person. Here's some advice on getting through hard times. Having A Hard Time synonyms. Top synonyms for having a hard time (other words for having a hard time) are having trouble, struggling and difficulty.

currentpos = 0
unenckey = ['a', 'e', 'f', 'h', 'i', 'k', 'm', 'o', 'r', 's', 't', 'w']
enc = "ztxhcccczxbatnnsqhlllowqtdhdzxveqmvbanmfxzibbaqwojrdkls"

for char in enc:
    if char in unenckey:
        print(char)

Have a hard time, Time spent in a prison, often implied to be as unpleasant as possible. When we catch these criminals, they're going to be doing at least 20 years of hard time. By stating you are having a hard time you are letting someone know you are having difficulty with something. This could be something physical or mental and something that could be overcome with effort. Here are some examples: " I'm having a hard time writing.

Do you want to ensure that your while loop always breaks by updating your code as follow?

currentpos = 0
unenckey = ['a', 'e', 'f', 'h', 'i', 'k', 'm', 'o', 'r', 's', 't', 'w']
enc = "ztxhcccczxbatnnsqhlllowqtdhdzxveqmvbanmfxzibbaqwojrdkls"
for unenc in enc: 
    #print(unenc)
    while True:
        if unenc == unenckey[currentpos]:
            currentpos = 0
            print(unenc)
            break
        elif unenc == 'q':
            print(' ')
            break
        else:
            if currentpos == 11:
                currentpos = 0
            if currentpos != 11:
                currentpos = currentpos + 1
                break #Make sure your while loop breaks!

The truth of the matter is there is actually no need for the while loop` if we will always end it with a break. I am just leaving it there because you have indicated that this is for educational purpose.

have a hard time, have a hard time meaning, definition, what is have a hard time: to have a lot of problems or bad experie: Learn more. There are a good number of men who can orgasm just fine on their own, but have a hard time getting there with a partner. In these cases, masturbation is one of the most frequent causes of orgasmic

Hard-time Synonyms, Hard-time Antonyms, What to do when you are going through a hard time? The main female sexual problem, simply stated, is that many women don’t have orgasms or have difficulty reaching orgasm. Ninety-five percent of women who aren’t having orgasms are actually pre-orgasmic: they are capable of orgasm, but they need help learning how to achieve orgasm.

'having {a hard time / hard time / hard times} understanding , 'A hard time' is typically used when someone or a group has difficulty coping in a particular situation. Often followed by a present participle, it can describe one  SHARON Stone has opened up on the tragic death of her ex Steve Bing, admitting that she is having a “hard time” coping with the news. The 55-year-old, who previously dated actress and m…

Article in “having (a) hard time”, It's odd that Google returns equally frequent hits. This is a common English colloquialism in its complete form (a hard time) but hearing/reading it without the​  Can I guy be turned on but still have a hard time getting a hard on? - Sexuality Question

Comments
  • What do you expect the program to do once currentpos reaches 11? Right now you just start over from 0. You probably want to break out of the inner loop also.
  • Just a word of advice: Try to have meaningful variable names and if they are multiple words, separate them using _. Although currentpos isn't the worst, unenckey or enc are weird imo. Would help you when debugging / reading through code.
  • I understand that you are trying to print the chars of enc that appears also on unenckey, is that correct?