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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:03:51+00:00 2026-06-13T07:03:51+00:00

May I kindly ask you for help. I must write a program in python

  • 0

May I kindly ask you for help.

I must write a program in python for homewrok which it asks two competitors alternately for one single letter. The program is over when there is no such word in dictionary (I imported dictionary which it is in text format that I get from teacher).

Here is how it should look like:

Competitor 1, letter a: m

Competitor 2, letter b: o

Competitor 1, letter a: u

Competitor 2, letter b: s

Competitor 1, letter a: e

Competitor 2, letter b: i

There is no such word mousei in dictionary!

And here is how I started:

dictionary=open("dictionary.txt", encoding="latin2").read().lower().split()
a=input("Competitor 1, letter a:")
b=input("Competitor 2, letter b:")
word=a+b

while word in dictonary:
      a=input("Competitor 1, letter a:")
      word=word+a
      b=input("Competitor 2, letter b:")
      word=word+b

print("There is no such word" ,word, "in dictionary!")

But something is wrong. Because when I start program and I write first two letters. It says there is no such word in dictionary.

Please help me!

One more thing: The game must stop immediately after the first wrong character. Could you please show how to make this.

  • 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-13T07:03:52+00:00Added an answer on June 13, 2026 at 7:03 am

    That’s because your condition is wrong! You shouldn’t check if the word is in dictionary, but if there is a word in the dictionary that starts with the word!

    Here is one possible solution (maybe not the prettiest one):

    word_ok = True
    dictionary=open("dictionary.txt", encoding="latin2").read().lower().split()
    a=raw_input("Competitor 1, letter a:")
    b=raw_input("Competitor 2, letter b:")
    word=a+b
    
    while word_ok:
            word_ok = False
            for dict_word in dictionary:
                if dict_word.startswith(word):
                    word_ok = True
                    break
            if word_ok:                                
                a=raw_input("Competitor 1, letter a:")
                word=word+a
                b=raw_input("Competitor 2, letter b:")
                word=word+b
            else:
                break
    
    print("There is no such word" ,word, "in dictionary!")
    

    EDIT:

    OK, here is a kind of compilation from the other answers. Note that encoding is not a valid keyword parameter to the builtin open() function. If you want to specify the encoding, use codecs.open(). Note as well that the word check is done twice within the while loop, after each competitor’s input.

    import codecs
    
    dictionary = codecs.open('dictionary.txt','r',encoding='latin2').read().lower().split()
    
    # Word we will build
    word = ''
    
    while True:
        letter = raw_input("C1: ")
        word = word + letter
        if not any(known_word.startswith(word) for known_word in dictionary):
            break
    
        letter = raw_input("C2: ")
        word = word + letter
        if not any(known_word.startswith(word) for known_word in dictionary):
            break
    
    print "There is no such word", word, "in dictionary!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

May i ask you how can i calculate the period by deduct two time
I write a program in WINCE5(c# 2.0) and want to interaction with my web
I am new to using XPath and this may be a basic question. Kindly
I need some help in creating an Oracle SQL which I will execute in
I searched link from where one may learn Wordpress not only starting level but
I'm binding two AutoCompleteModified objects to one another; meaning you type in one and
May I install a search provider/accelerator remotely in Internet Explorer 8? I dont want
May I know how could I pass the value of driver from code behind
May I know a way to change the Google Map marker color via Javascript..
May be obvious but I tried searching and can't figure it out. I am

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.