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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:23:45+00:00 2026-06-12T21:23:45+00:00

I created a simple program that lets you input a set of numbers, then

  • 0

I created a simple program that lets you input a set of numbers, then creates a randomly generated list of pairs from the data that was given by the person.
How can I save the data (as a Windows file) once it finishes?
This is my code:

import random as ran
import easygui as eg
nList=vList=eg.multenterbox(msg="Enter the names of the people:"
                , title="Random Pair Generator"
                , fields=('Name:', 'Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:','Name:',)
                , values=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20']
                )

index=0
x=''
y=''
pList=[]
pair=''

while not(index==len(nList)):
   x=nList[index]
   y=ran.choice(vList)
   pair=x+'; '+y
   pList.insert(index, pair)
   vList.remove(y)
   index= index+1

    eg.textbox(msg="These are the pairs generated."
                , title= "Random Pair Generator"
                , text= str(pList)
                , codebox=0
                )

I just want to save pList as a file, anywhere on my computer (preferably somewhere I can specify).
Also, this loop creates an issue. It doesn’t raise an error with syntax or anything, but the output is not what I want it to be.

What it does is it uses each value from nList, then picks a random value from vList, and then puts those as one object into pList. However, the problem arises that when I have it delete the output of “y” from vList, it also removes it from nList.

Example: If nList contains 5 objects: [1, 2, 3, 4, 5] and vList has the same objects [1, 2, 3, 4, 5]. It would select a random number from vList for every value in nList.
However, once a variable from vList is chosen, it is removed from the list. The problem is that say pList starts as [1; 2] where 1; 2 is one object, the next object would start at 3. It would skip over 2 because 2 was already used as a ‘y’ value.

  • 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-12T21:23:46+00:00Added an answer on June 12, 2026 at 9:23 pm

    If you just want to save the list of pairs in the same format as it was displayed in your eg.textbox, add something like this to end of your program:

    filename = eg.filesavebox(msg=None
                            , title='Save Pair List'
                            , default="pairs.txt"
                            , filetypes=['*.txt']
                            )
    
    with open(filename, 'wt') as output:
        output.write(str(pList)+'\n')
    

    You could write each pair of the list on a separate line of the output file like this:

    with open(filename, 'wt') as output:
        for pair in pList:
            output.write(pair+'\n')
    

    Using the with statement means the file will be closed for you automatically after the block of code it controls is finished.

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

Sidebar

Related Questions

I have a simple program that creates a thread, loops twenty times and then
I created a really simple Java program that creates a java.net.ServerSocket on an open
I have created a simple program that i want to replace some chars with
I want help with my UIScrollView sample. I created a simple program that scrolls
I'm making a simple program that copies files created or modified since it was
So I created a simple hello world program that uses ksoap2 on Android 2.3
I created a simple program that demonstrates the runtime error I'm getting with my
I have created a simple program that draws shapes within command prompt. I am
I created a simple program that takes the path of a directory as an
I created a simple program that uses condition variables to create synchronization between two

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.