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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:23:27+00:00 2026-05-31T21:23:27+00:00

I have to write a program in python where the user is given a

  • 0

I have to write a program in python where the user is given a menu with four different “word games”. There is a file called dictionary.txt and one of the games requires the user to input a) the number of letters in a word and b) a letter to exclude from the words being searched in the dictionary (dictionary.txt has the whole dictionary). Then the program prints the words that follow the user’s requirements. My question is how on earth do I open the file and search for words with a certain length in that file. I only have a basic code which only asks the user for inputs. I’m am very new at this please help 🙁
this is what I have up to the first option. The others are fine and I know how to break the loop but this specific one is really giving me trouble. I have tried everything and I just keep getting errors. Honestly, I only took this class because someone said it would be fun. It is, but recently I’ve really been falling behind and I have no idea what to do now. This is an intro level course so please be nice I’ve never done this before until now 🙁

print
print "Choose Which Game You Want to Play"
print "a) Find words with only one vowel and excluding a specific letter."
print "b) Find words containing all but one of a set of letters."
print "c) Find words containing a specific character string."
print "d) Find words containing state abbreviations."
print "e) Find US state capitals that start with months."
print "q) Quit."
print

choice = raw_input("Enter a choice: ")
choice = choice.lower()
print choice

while choice != "q":
    if choice == "a":
        #wordlen = word length user is looking for.s

        wordlen = raw_input("Please enter the word length you are looking for: ")
        wordlen = int(wordlen)
        print wordlen

        #letterex = letter user wishes to exclude.
        letterex = raw_input("Please enter the letter you'd like to exclude: ")
        letterex = letterex.lower()
        print letterex
  • 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-05-31T21:23:28+00:00Added an answer on May 31, 2026 at 9:23 pm

    To open the file, use open(). You should also read the Python tutorial sec. 7, file input/output.

    Open a file and get each line

    Assuming your dictionary.txt has each word on a separate line:

    opened_file = open('dictionary.txt')
    for line in opened_file:
        print(line) # Put your code here to run it for each word in the dictionary
    

    Word length:

    You can check the length of a string using its str.len() method. See the Python documentation on string methods.

    "Bacon, eggs and spam".len() # returns '20' for 20 characters long
    

    Check if a letter is in a word:

    Use str.find(), again from the Python sring methods.


    Further comments after seeing your code sample:

    • If you want to print a multi-line prompt, use the heredoc syntax (triple quotes) instead of repeated print() statements.
    • What happens if, when asked “how many letters long”, your user enters bacon sandwich instead of a number? (Your assignment may not specify that you should gracefully handle incorrect user input, but it never hurts to think about it.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asked to write a program using python for an assignment. I
I have to write a program that read from a file that contains the
So I have the following read and write file program for an Array. How
I need to write a program used internally where different users will have different
On Windows 7, I have a command-line program that fails due to file write permission
I have a python practise project. I'm going to write a GUI program which
I'd like to write a python program that allows the user to key an
I am new to Python and currently have to write a python program/script to
I am trying to write a program using python-fuse, but I can't get file
Hello I am trying to write a program in python that asks the user

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.