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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:06:49+00:00 2026-06-16T01:06:49+00:00

I have a basic code that just simply loops over and print some numbers

  • 0

I have a basic code that just simply loops over and print some numbers in python. My problem was that I needed a different way to print my output since I wanted them to be on the same line. (The standard python print statement just prints stuffs on a new line). After doing some research i discovered that I could do something like this

    import random
from sys import stdout
    i= 0
    while i < 100:
        j = 0
        while j < 4:
            k =0
            while k < 4:
                sys.stdout.write(random.randint(0, 9))
                k += 1
            sys.stdout.write(" ") 
            j += 1   
        i += 1
        print "\n" 

This works like charm when I run it using IDLE — python’s ide, my only problem is that whenever I try to run it from the terminal it complains about this

    CallingCard $ python numGenerator.py 
Traceback (most recent call last):
  File "numGenerator.py", line 13, in <module>
    sys.stdout.write(random.randint(0, 9))
NameError: name 'sys' is not defined
CallingCard $ 

Wondering what might be the problem since running it from IDLE, FYI I am using python 2.7.3

  • 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-16T01:06:50+00:00Added an answer on June 16, 2026 at 1:06 am

    Found the solution. Deep thinking helps sometimes
    Below is the code

        i= 0
    while i < 100:
        j = 0
        while j < 4:
            k =0
            while k < 4:
                sys.stdout.write("%s" % random.randint(0, 9))
                k += 1  
            sys.stdout.write(" ") 
            j += 1   
        i += 1
        print "\n"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some very basic semaphore code that works great on Linux, but cannot
I have some really simple code that's just not working: int[] manualPixels = new
Basic question here - I have many lines of code that look something like:
I have some basic jquery code sitting in the header of the header file
I have some basic PHP code: $raceramps56[short] = My Test Product; $leftMenu = '<div
I have some very basic SignalR code running on the js client: var conn
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
We have a class library that does some basic operations similar to an ORM,
I have a program very basic with just functions and variables and performs some
I'm writing a basic bootloader just to the point where I have some sort

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.