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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:21:27+00:00 2026-05-28T05:21:27+00:00

I am new at programming. I am trying to match a number (given by

  • 0

I am new at programming. I am trying to match a number (given by the user) to the numeric values of words in a file. Example a=1. b=2, c=3, A=1, B=2, so that if the user enters “2” then the output would be all words in the list that match 2.

userinput = raw_input("Please, enter the gematric value of the word: ")
inputfile = open('c:/school/dictionarytest.txt', 'r')
inputfile.lower()
output = []
for word in inputfile:
    userinput = ord(character) - 96
    output.append(character)
    print output
inputfile.close()

I am somewhat new at this and the syntax is not that familiar. Could someone please help? Thank you

Edit1- example the user enters the number 7. If the word bad (b=2,a=1,d=4) is on the list the output would be “bad”, and any other words that match the addition of their characters.

  • 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-28T05:21:28+00:00Added an answer on May 28, 2026 at 5:21 am

    Here’s the code with comments that describe it in detail:

    # ask user for an input until an integer is provided
    prompt = "Please, enter the gematric value of the word: "
    while True: # infinite loop
        try:        
            # ask user for an input; convert it to integer immediately
            userinput = int(raw_input(prompt))
        except ValueError: # `int()` can't parse user input as an integer
            print('the gematric value must be an integer. Try again')
        else:
            break # got an integer successfully; exit the loop
    
    # use `with` statement to close the file automatically
    # `'r'` is default; you don't need to specify it explicitly
    with open(r'c:\school\dictionarytest.txt') as inputfile:
        #XXX inputfile.lower() # WRONG!!! file object doesn't have .lower() method
    
        # assuming `dictionarytest.txt` has one word per line
        for word in inputfile: # read the file line by line
            word = word.strip() # strip leading/trailing whitespace
            if gematric_value(word) == userinput:
               print(word) # print words that match user input
    

    Where gematric_value() function is:

    def gematric_value(word):
        """Sum of numerical values of word's characters.
    
        a -> 1, b -> 2, c -> 3; A -> 1, B -> 2, etc
        """
        # word is a string; iterating over it produces individual "characters"
        # iterate over lowercased version of the word (due to A == a == 1)
        return sum(ord(c) - ord('a') + 1 for c in word.lower())
    

    Note: don’t use the above comment style in your code. It is acceptable only for educational purposes. You should assume that a reader of your code is familiar with Python.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to programming and I am trying to write a program that
i been thinking of a new programming language. Before trying to implement it i
i am new in programming under linux and trying to get working this code:
I'm fairly new to iPhone programming and am trying to implement a double-component PickerView.
I am new to programming. I have been trying to write a function in
I'm new to windows programming and I'm trying to get notified of all changes
New to Linux programming in general. I am trying to communicate with a kernel
I'm new to iPhone programming, and I'm trying to make a simple program without
I am new in iPhone programming. At the moment I am trying to recognize
I'm somewhat new to object oriented programming in Javascript and I'm trying to build

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.