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 6893917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:43:04+00:00 2026-05-27T06:43:04+00:00

I am trying to receive user input and then put it into a list.

  • 0

I am trying to receive user input and then put it into a list. I have a working version, however, I feel as though it is redundant(the first block seems redundant, though if I take it away, it doesn’t work). Any way this can be improved?
Thanks

def pastChoice():
     choice = raw_input("> ")
     prevMove = []
     prevMove.append(choice)

for i in prevMove:
     choice = raw_input("> ")
     prevMove.append(choice)
     print prevMove

pastChoice()

I am making a game and I want to show the user what choices they have already made.

Ex. Type ‘history’ if you would like to see previous choices

[‘a’,’a’,’c’,’b’]

  • 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-05-27T06:43:05+00:00Added an answer on May 27, 2026 at 6:43 am

    I’m not sure about your intentions for this code, but this is roughly equivalent:

    def pastChoice():
        prevMove = []
    
        while True:
            choice = raw_input("> ")
            prevMove.append(choice)
            print prevMove
    pastChoice()
    

    the block:

     choice = raw_input("> ")
     prevMove = []
     prevMove.append(choice)
    

    asks user for input and appends it to prevMove, so at loop start, the condition i in prevMove evaluates i to the first element in prevMove, then because in the second block you’re appending new elements to prevMove, the iteration continues over those the newly appended elements and the loop never ends.

    If you remove the first block, but keep the for loop, it won’t work because there are no elements inside prevMove and therefore nothing to iterate over.

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

Sidebar

Related Questions

I am basically trying to return from a method which reads user input from
I have a website registration page, and I'm trying to compile a list of
Im trying to break the input and the processing into two parts so that
I'm trying to use regex to validate input from the user, I'm wanting to
I am trying to display autocomplete results for a list of managers. I have
I'm trying to create a calculator where the user can put in 4 values,
I'm trying to build a simple autocomplete list: DOM: <input id=example/> <div id=results></div> Javascript:
I am trying to write a simple activity that received from the user its
I am trying to receive a json object back from php after sending data
I am trying to receive an image from the Android Gallery via an ACTION_SEND

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.