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

  • SEARCH
  • Home
  • 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 8573217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:11:59+00:00 2026-06-11T19:11:59+00:00

Here is a dumbed down version of my program that I am using as

  • 0

Here is a dumbed down version of my program that I am using as an example.

I know that using GOTO is bad practice, because it leads to sloppy and confusing code, however it would be perfect for solving this problem that I have (problem detailed at bottom of post).

def prompt():
    while True:
        user_input = raw_input:
        if input == '?':
            print help_o
        elif not user_input.isalpha():
            print "You entered bad characters"
        elif user_input == 'r': ##Restart
            ???????????
        else:
            return user_input


load_word_list() ##Load words into list

for word in wordList: ##Loop that needs to restart
    for i in range(5):
        to_speak = "Spell, %s" %word
        subprocess.Popen(['espeak', to_speak])
        answer = prompt()
        if answer != word:
            print "You got it wrong"


#Print results

At the Prompt, I want to reload the wordList list and restart the outer for loop.

With GOTO I could just put in place of ????… GOTO load_word_list().

But since this is Python (and Python is about good code), What is the Pythonic way to solve this problem?

  • 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-11T19:12:00+00:00Added an answer on June 11, 2026 at 7:12 pm

    Another take on jsbuenos solution. This actually does re-run the outer for loop.

    def prompt():
        while True:
            user_input = raw_input()
            if input == '?':
                print help_o
            elif not user_input.isalpha():
                print "You entered bad characters"
            elif user_input == 'r': #Restart
                raise RestartException
            else:
                return user_input
    
    
    class RestartException(Exception):
        pass
    
    
    while True:
        load_word_list() ##Load words into list
        try:
            for word in wordList: ##Loop that needs to restart
                for i in range(5):
                    to_speak = "Spell, %s" %word
                    subprocess.Popen(['espeak', to_speak])
                    answer = prompt()
                    if answer != word:
                        print "You got it wrong"
        except RestartException:
            # catch the exception and return to while loop
            pass
        else:
            # exit while loop
            break
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Just a quick question as I haven't been using jQuery for that long. Is
I have read several articles here and else where that it is OK to
I'm having trouble building a specific query to select records. Here is a dumbed
My program has a component - dubbed the Scheduler - that lets other components
I realize that similar questions have been asked about this before here on SO,
I am using javascript to load up an Action and finding that when the
I'm using Paypal website payment standard to subscription for my site. Here is the
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }

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.