Python Forum
Something wrong with my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Something wrong with my code
#1
Firstly I'm not a coder and at 80 I doubt whether I will ever have enough brain cells to attempt such a task.

But I do enjoy making Wordsearch Puzzle books. It keeps the little brain cells from going completely dead. The reason I'm here is that ChatGPT gave me a Python code

```python
import random

def generate_words(subject, word_length, num_words):
    words = []
    letters = 'abcdefghijklmnopqrstuvwxyz'
    for _ in range(num_words):
        word = ''.join(random.choice(letters) for _ in range(word_length))
        words.append(subject + word)
    return words

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

def main():
    subject = input("Enter the subject of the words: ")
    word_length = int(input("Enter the number of characters per word: "))
    num_words = int(input("Enter the number of words to generate: "))
    folder_path = input("Enter the folder path to save the file (e.g., C:/Users/Username/Desktop/WordGenerator): ")

    words = generate_words(subject, word_length, num_words)
    save_words(words, folder_path)

if __name__ == '__main__':
    main()
```
for a Word Generator that I could run on Windows but there is something wrong with the code. I ran it in Thonny and it gave this.....

SyntaxError: invalid syntax
Word Generator.py line 1

But there's nothing on line 1, so can anyone tell me what's gone wrong, please remember that I have hardly any knowledge about coding.

Thanks a lot
deanhystad write Jul-03-2023, 02:43 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
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 520 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,636 Mar-27-2023, 07:38 AM
Last Post: buran
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,318 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,895 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,650 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Wrong code in Python exercise MaartenRo 2 1,564 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,652 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  VS Code debugger using wrong Python environment topfox 0 2,547 Jun-09-2021, 10:01 AM
Last Post: topfox
  What is wrong with my code??? MrLeads 15 5,141 Sep-16-2020, 02:00 PM
Last Post: MrLeads
  Can somebody check what is wrong with my code? hplus_liberation 4 2,656 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