Python Forum
How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu
#1
Hello. Just recently I put my BBS back online after nine years, and I am trying to write a python-based game -- for my BBS.

Before I continue, let me inform you that I am 70 years old, I am NOT a programmer, and I do not know any programming languages.

However, following the coding example of another open-source external that was written for my BBS, I have made some progress.

But, due my lack of expertise, I am stuck in several areas. Let me just discuss one of them in this current message.

I have a long list of quotes -- meaning several thousand of them -- in a text file, one quote per line. I have placed this text file in the "strings" folder for the python module that I am building for my BBS.

I have already imported both "random" and "string" at the top of my main.py file.

So, what I would like to do is create a function -- which I assume I must in some way declare at the top of my main.py file -- with an accompanying menu command, which I can add to the main menu in my python module.

I have done a lot of online research, and found a lot of different methods for doing what I want to do, which has left me rather confused.

Basically, once a user enters my game on my BBS -- meaning the python module -- I want them to be able to type a one-letter command that is shown on the main menu of the game module.

Typing this one-letter command will then have my game module randomly print one quote from the text file on the user's screen.

I don't know if this list of several thousand quotes would be referred to as a list, a dictionary, a set or what. As I said, I am very new to all of this, and being seventy, it is hard for my mind to grasp all of this stuff.

Being as this text file is one MB in size, I am assuming that it would not be wise to load it all into memory at once.

So, if anyone here has the patience to walk me through this step-by-step, explaining how to set this up, and how to link the command on the Main Menu, with clear examples of exactly what to type, and where to put it in my modules files, I would be most appreciative.

Thank you in advance.
Reply


Messages In This Thread
How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu - by BillKochman - Apr-01-2024, 09:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Cannot get cmd to print Python file Schauster 11 398 May-16-2024, 04:40 PM
Last Post: xMaxrayx
  problem with print command in super() akbarza 5 690 Feb-01-2024, 12:25 PM
Last Post: deanhystad
  pyaudio seems to randomly halt input. elpidiovaldez5 2 444 Jan-22-2024, 09:07 AM
Last Post: elpidiovaldez5
  Problem with code / audio is playing randomly, not matching csv requirements Daniel_kcr 2 690 Sep-07-2023, 05:09 PM
Last Post: deanhystad
  Start print a text after open an async task via button Nietzsche 0 743 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,171 Jan-16-2023, 07:38 PM
Last Post: Skaperen
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,173 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  python sql query single quote in a string mg24 1 1,133 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  python run all py files from main py file mg24 6 1,449 Oct-12-2022, 04:41 AM
Last Post: mg24
  Saving the print result in a text file Calli 8 1,931 Sep-25-2022, 06:38 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020