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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:12:23+00:00 2026-05-18T12:12:23+00:00

Alright, if you run the below code in Python it only prints the first

  • 0

Alright, if you run the below code in Python it only prints the first letter of the question variable, however it prints the rest just fine. This only happens \when I have the for loop function inside of my Python script. Any ideas on how to fix it so I get the entire question variable printing?

    import random
    global nouns
    global verbs
    global question
    nouns =["website","browser","server","printer","computer","disc","software","desktop","a internet connection","the internet","site","forum","smf forum","phpbb forum","money making website","money making blog","firefox","chrome","opera","",""]
    verbs = ["cosntruct","build","create","design","update","reconstruct","clean","fix","repair","browse","discover","formualte","form","plan"]
    question = ["How do I","How would I", "how do i", "how would i", "what is a", "what is the", "how would i", "how should i", "when does a", "When does a", "How should I"]


    def q_gen():
       global nouns
       global verbs
       global question
       noun_pick = random.choice(nouns)
       verb_pick = random.choice(verbs)
       question = random.choice(question)
       create = question+" "+verb_pick+" "+noun_pick+"?"
       print create

    num_count = 0
    for num_count in range(1, 100):
       num_count=num_count+1
       q_gen()
  • 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-18T12:12:24+00:00Added an answer on May 18, 2026 at 12:12 pm

    This is happening because you are overwriting the global variable question with one of the values of question at this line:

    question = random.choice(question)
    

    This means that the following occurs:

    question = [...] # question is a list of strings
    question = random.choice(question) # question is a single string
    question = random.choice(question) # question is a character from that string
    

    The solution is to replace the variable name with something else:

    question_pick = random.choice(question)
    create = question_pick+" "+verb_pick+" "+noun_pick+"?"
    

    A few notes on style

    There are a number of improvements you can make to your code. These changes could improve readability, improve performance, and otherwise make your code more idiomatic.

    • Declaring variables. This is not done in Python. When you assign to a variable, it springs into existence. This includes for statements

      global a # Unnecessary and dangerous
      a = 0
      
    • Iteration. When you say for x in ..., you’re executing a suite of statements again and again. Each time you go through the suite, x is assigned to the next item. You do not need to assign or increment x yourself.

      x = 0 # Not necessary; x is about to be assigned to the first
            # element of range(10), which is 0
      for x in range(10):
          ...
          x = x + 1 # Not necessary; as soon as this statement is done,
                    # x will be assigned to the next element of range(10)
      
    • Globals.

      • You don’t need them. When you use name = ..., you are creating a module-level variable. Each variable is accessible everywhere in your module (that is, in your current .py file)

      • They’re dangerous. If some other module is using a variable named name, you could be in for a nasty surprise. Keep this in mind if you plan to develop this code further.

    • String formatting. The idea is that you create a template, then put tags where you want values dropped in. The %s tag means “Interpret the next variable as a string and put it here”.

      create = "%s %s %s?" % (question, verb_pick, noun_pick)
      
    • Style. Python has a style guide known as PEP 8. Making sure your code adheres to PEP 8 keeps it readable and makes it look more similar to other Python code. For example, operators should be surrounded by a single space, there should be a single space after a comma, etc.

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

Sidebar

Related Questions

Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright, quick question. A server is running in Eastern Time. PHP program needs to
Alright, PHP is throwing this error at me (in the log) when I run
Alright well, I connect to 3 different ip's when I run this script. It
public boolean addPoint(Point p){ points.add(p); extremes(); return points.add(p); } Alright so when I run
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, currently I have my SWF hitting a php file that will go and
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright, I'm trying to read a comma delimited file and then put that into
Alright, after doing a ton of research and trying almost every managed CPP Redist

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.