Python Forum
Something wrong with my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Something wrong with my code
#5
(Jul-03-2023, 04:21 PM)FabianPruitt Wrote: You were right it does spew out Gibberish. Is there a way to get it to spew out recognisable words in English instead?

Is there any Coder on this forum that would undertake an update of this code to make it into a decent piece of software?

I would pay for the person's time of course.
It's a task that's not so easy when talking about making recognisable words in English.
There are modules like eg random-word that will generate a working random English words.
Another way is to eg use chatGPT API trough Python,seach web.

For fun can use random-word module json database and mix it with code you posted.
This just save a random word,of course adding something like subject will be difficult.
word_length, num_words is possible to add without to much difficulty.
(Jul-03-2023, 04:21 PM)FabianPruitt Wrote: Firstly I'm not a coder and at 80 I doubt whether I will ever have enough brain cells to attempt such a task.
Cool,but should start with some easier task than this.
import random
import json

def generate_words(word_length=4):
    with open('words.json') as fp:
        result = json.load(fp)
        word, _ = random.choice(list(result.items()))
    return word

def save_words(word, folder_path):
    file_path = folder_path + '/generated_words.txt'
    with open(file_path, 'w') as file:
        file.write(word)
    print(f"Words saved successfully to '{file_path}'.")

def main():
    subject = input("Get a random words <Enter>: ")
    folder_path = input("Enter the folder path to save the file")
    word = generate_words()
    save_words(word, folder_path)

if __name__ == '__main__':
    main()
Output:
sauciness
Reply


Messages In This Thread
Something wrong with my code - by FabianPruitt - Jul-03-2023, 02:19 PM
RE: Something wrong with my code - by deanhystad - Jul-03-2023, 02:48 PM
RE: Something wrong with my code - by FabianPruitt - Jul-03-2023, 04:21 PM
RE: Something wrong with my code - by deanhystad - Jul-03-2023, 04:47 PM
RE: Something wrong with my code - by snippsat - Jul-03-2023, 08:52 PM
RE: Something wrong with my code - by Pedroski55 - Jul-03-2023, 10:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 578 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,738 Mar-27-2023, 07:38 AM
Last Post: buran
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,389 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 2,009 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,807 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Wrong code in Python exercise MaartenRo 2 1,601 Jan-01-2022, 04:12 PM
Last Post: MaartenRo
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,682 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  VS Code debugger using wrong Python environment topfox 0 2,585 Jun-09-2021, 10:01 AM
Last Post: topfox
  What is wrong with my code??? MrLeads 15 5,240 Sep-16-2020, 02:00 PM
Last Post: MrLeads
  Can somebody check what is wrong with my code? hplus_liberation 4 2,689 Sep-16-2020, 05:52 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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